Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mikebird
Aged Yak Warrior
529 Posts |
Posted - 2011-03-29 : 11:02:26
|
| During testing, across many DBs, I want to avoid playing with parameters to get reasonable spreads of activity, where a DB could have action over a week in 1950, or nothing until yesterday, or some bits & bobs here & there...Using the core of the FROM clause, and getting just a date and count from that, and not wanting to manually set a having count > 60, I creamed the top row, and will set the focus from date_from and date_to parameters around that date, by about a month, or more, and I'll eventually apply this to each stored procedure individually. What's the best way to use this outcome, be this a date, or sales volume? I'm thinking of putting this into #peak_orderdateHow do I do that within an existing stored procedure? Temp table, or set the @Date_From and @Date_To, ignoring input from outside..?It's simple, but I could use advice...select top 1 orderdate from (select orderdate ,count(*) as count FROM PatientsWithDatesRpt PVINNER JOIN Orders OON O.patient = PV.patuIdINNER JOIN OrdersWithDatesRpt OVON OV.orduId = O.uIdINNER JOIN LimbTypes LTON LT.uId = O.limbTypeINNER JOIN LimbTypeCodes LTCON LTC.uId = LT.limbTypeCodeLEFT OUTER JOIN Amputations AON A.uId = O.amputationINNER JOIN AmpTypes ATYON ATY.uId = A.ampTypeINNER JOIN AmpLevels ALON AL.uId = ATY.ampLevelGROUP BY orderdate) tORDER BY count desc |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2011-03-29 : 19:12:20
|
| I'm not clear on what you are trying to accomplish. Are you trying to set the stored procedure's parameter's test values from within the stored procedure?=======================================Elitism is the slur directed at merit by mediocrity. -Sydney J. Harris, journalist (1917-1986) |
 |
|
|
mikebird
Aged Yak Warrior
529 Posts |
Posted - 2011-03-30 : 04:19:00
|
| Tooo simple to dictate the limits manually. Results could be empty. I want to group on order_date and see where the peak is, as I said - the majority per month - this month, or 10 years ago... Then set the date range around that month. This is for testing - to ensure we see a relevant date with the most results. Once the report is meaningful, I'd then leave the parameters for the person running the report to choose |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2011-03-30 : 18:31:18
|
| GROUP BY DateAdd(month, DateDiff(month, 0, orderdate), 0)ORDER BY count DESC???=======================================Elitism is the slur directed at merit by mediocrity. -Sydney J. Harris, journalist (1917-1986) |
 |
|
|
|
|
|
|
|