![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
Here is an example of what I'm trying to do: Populate a grid(below) on a .net dashboard web page with counts of various types of activity(y axis) that would be distributed into bins(x axis) . The datasource would be a single table or simple view(no aggregates). The bins would represent increments in specific criteria, which would NOT necessarily involve sequential values such as days of the month. (The actual page will contain several grids, each having a different number of bins. I would like to use the same code for all grids, if possible -- sending the datasource, number of bins, and bin criteria as input parameters.) ... I could call 20 different stored procedures, each having n SELECT statements, but we all know a whole list of reasons why that's a bad idea. |
#12
| |||
| |||
|
|
I could call 20 different stored procedures, each having n SELECT statements, but we all know a whole list of reasons why that's a bad idea. Why would you have different procedures for different activities? |
|
Of course, this assumes that the data model is set, and neither that is clear to me. Then again, if you post what you have now, we may get a better grip of where you're heading. |
#13
| |||
| |||
|
#14
| |||
| |||
|
#15
| |||
| |||
|
|
Activites(1-n) in a single grid are not all pulled from the same table or view, and some of the criteria would differ. So I don't believe a GROUP BY clause on a single dataset would fit the problem. |
|
My "procedural language programmer" solution would be to open one connection to the db and grab all the information at once, retrieving all the activity rows in individual activity parameters. I could then parse each parameter value into the appropriate bins with vb behind the page. |
|
I use bin variables @d1-@d5 rather than literals 1, 7, 20, 25, 60 because I'm hoping there is a way to programmatically vary the number and values of bin boundaries, through input parameters or some other means, and make this thing elegant. |
#16
| ||||
| ||||
|
|
Nevertheless, the procedure you post has an input parameter. If you need to retrieve data for more than one code, you need to make multiple calls, which is not effecient. |
|
Really why you go for your lists, I don't know. You could have a single procedure that reads all tables and then returns multiple result sets that you receive in a dataset of datatables. At least you minimize the network roundtrips. |
|
I use bin variables @d1-@d5 rather than literals 1, 7, 20, 25, 60 because I'm hoping there is a way to programmatically vary the number and values of bin boundaries... That's not that easy. A SELECT query returns a table, and a table has fixed number of columns, and each describes a distinct entity. To have a variable number of columns or variably named columns, you need to engage in dynamic SQL. Which may not be a bad choice for this task, presuming that you can deal with the performance issues. But running it all in T-SQL is not that fun; VB .Net might be a better venue. |
|
your cross join example... ...put the intervals in a real table, and have it configurable. |
#17
| |||
| |||
|
#18
| |||
| |||
|
|
That has been the fundamental question all along. "How complex and/or flexible can a single stored procedure be, and still be efficient?" What I'm learning is that they can be very complex, but not as flexible as c, vb, etc. |
|
I could build all the input parameters in vb and send them to the wrapper, and vary the number of calls the wrapper makes to the subproc. That way, I would only have to change the code in my page when the number or value of bins change. Wouldn't have to edit the stored procs. Does it look like a reasonable solution to you? Is it reasonably efficient? |
![]() |
| Thread Tools | |
| Display Modes | |
| |