Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Use returned data inside procedure
Message
 
 
À
22/09/2015 10:18:38
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01624886
Message ID:
01624920
Vues:
41
>>>Both need totals, no matter if it is weekly. My week is based on Sunday first day. I use datepart(wk, date), it use client's machine?
>
>>OK, sorry for being a bit dense, but I want to make sure I understand what results are needed.
>
>>Let's say the first result set has counts summarized for every day in September. So the first result set would have 30 rows.
>
>>Would the 2nd result set look like this?
>
>WeekEnding             #Quotes    #column2     #column3         #column4
>9/5/2015               100           200               300              400
>9/12/2015             200           300               400              500
>9/19/2015             300           400               500              600
>9/26/2015             400           500               600              700
>10/3/2015             500           600               700              800
>NULL                    1500         2000            2500             3000
>
>>Is that would you want the 2nd result to look like? One row per week, plus a grand total?
>
>Absolutely, it's right.

In this case I suggest that stored procedure returns 2 result sets separately (using the same dynamic pivot technique). I also suggest to use GROUPING SETS to generate the total rows in both of them.

Check this blog post by Jacob Sebastian as how to create totals using GROUPING SETS
http://beyondrelational.com/modules/2/blogs/28/posts/10523/t-sql-tuesday-016-summarizing-data-using-grouping-sets.aspx
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform