Wednesday, March 28, 2012

Need to build a query

Hey. It's probably a very simple query but I'm not at all good in writing
T-SQL. Anyways, My environment is SQL 2005.
I need to write a stored proc which returns 4 columns to a C# app. All the
data comes from one table only.
The first column will just have 'Name of months'
The second column will have a sum of amount
(-sum of amount in jan in first row,
-sum of amount in feb in row 2,
-sum of amount in feb in row 3,
-sum of amount in feb in row 4)
The third row will have a sum of won per month for this year(just like 2nd
column),
The fourth row will have a sum of Lost per month for this year(just like 2nd
column
I'm very new to SQL 2005.
Thank you.Before we can help you, please help us:
http://www.aspfaq.com/etiquette.asp?id=5006
ML
http://milambda.blogspot.com/|||It sounds like you are trying to get 4 different datasets returned as 4
distinct rows in a single query, simply so you can display them as one
dataset. While this is possible, it is not advisable.
Your best bet is to select whatever the core data is that you will be basing
your calculations on and then process it in your application.
"Tejas Parikh" <TejasParikh@.discussions.microsoft.com> wrote in message
news:5BE2F352-33C6-4A02-88B1-9EC75F843B96@.microsoft.com...
> Hey. It's probably a very simple query but I'm not at all good in writing
> T-SQL. Anyways, My environment is SQL 2005.
> I need to write a stored proc which returns 4 columns to a C# app. All the
> data comes from one table only.
> The first column will just have 'Name of months'
> The second column will have a sum of amount
> (-sum of amount in jan in first row,
> -sum of amount in feb in row 2,
> -sum of amount in feb in row 3,
> -sum of amount in feb in row 4)
> The third row will have a sum of won per month for this year(just like 2nd
> column),
> The fourth row will have a sum of Lost per month for this year(just like
2nd
> column
> I'm very new to SQL 2005.
> Thank you.|||Never mind my last post. In your other post you explained clearly what you
were trying to do. I misunderstood your goals entirely.
"Tejas Parikh" <TejasParikh@.discussions.microsoft.com> wrote in message
news:5BE2F352-33C6-4A02-88B1-9EC75F843B96@.microsoft.com...
> Hey. It's probably a very simple query but I'm not at all good in writing
> T-SQL. Anyways, My environment is SQL 2005.
> I need to write a stored proc which returns 4 columns to a C# app. All the
> data comes from one table only.
> The first column will just have 'Name of months'
> The second column will have a sum of amount
> (-sum of amount in jan in first row,
> -sum of amount in feb in row 2,
> -sum of amount in feb in row 3,
> -sum of amount in feb in row 4)
> The third row will have a sum of won per month for this year(just like 2nd
> column),
> The fourth row will have a sum of Lost per month for this year(just like
2nd
> column
> I'm very new to SQL 2005.
> Thank you.sql

No comments:

Post a Comment