Philippe Renaud
asked on
SQL query
hello EE,
please look at this image and the way I retrive the results.
the select looks like this :
my problem is that the results are not in 1 line. i would like 1 line for each style1, style2, date, whrse_no
so Jan is 60, Feb is 60, MArch is 0 all that on 1 line.
then we have another 700 for Jan, 700 on feb etc.., well I would like that on a second line (no sum)
how could I do that ?
please look at this image and the way I retrive the results.
the select looks like this :
select Style1
, [Style2] = isnull(Style2, '')
-- , AddedBy = ''
, [DateAdded] = convert(smalldatetime, convert(varchar, DateAdded, 110))
, [Whrse_No] = isnull(Whrse_No, '')
, [January] = isnull(case when [Month] = 'January' then [Amount] end, 0)
, [February] = isnull(case when [Month] = 'February' then [Amount] end, 0)
, [March] = isnull(case when [Month] = 'March' then [Amount] end, 0)
, [April] = isnull(case when [Month] = 'April' then [Amount] end, 0)
, [May] = isnull(case when [Month] = 'May' then [Amount] end, 0)
, [June] = isnull(case when [Month] = 'June' then [Amount] end, 0)
, [July] = isnull(case when [Month] = 'July' then [Amount] end, 0)
, [August] = isnull(case when [Month] = 'August' then [Amount] end, 0)
, [September] = isnull(case when [Month] = 'September' then [Amount] end, 0)
, [October] = isnull(case when [Month] = 'October' then [Amount] end, 0)
, [November] = isnull(case when [Month] = 'November' then [Amount] end, 0)
, [December] = isnull(case when [Month] = 'December' then [Amount] end, 0)
from Tableau_Projections
where Style1 = '23336'
my problem is that the results are not in 1 line. i would like 1 line for each style1, style2, date, whrse_no
so Jan is 60, Feb is 60, MArch is 0 all that on 1 line.
then we have another 700 for Jan, 700 on feb etc.., well I would like that on a second line (no sum)
how could I do that ?
how do you differentiate the first January value from the second? Both have the same Style1, Style2, DateAdded and Whrse_No. We need a way be able to group the values together.
ASKER
Sorry its because i was removing the Time from the date. but in the real source table (second image) you see a time difference...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You wont like this but where I am working right now Im not allowed to use PIVOT.. (old SQL Server) I think of it before but I cant
Its a real pain.
What should I do of it ?
Its a real pain.
What should I do of it ?
ASKER
oh but hold on, you're right... I just have to do the sum and a group and it works I think.
Then for future posts: Use the correct tags. Cause SQL Server 2005 supports PIVOT.
ASKER