Tuesday, March 20, 2012

Case in SqlServer

Hi,
I have a table and field below.

Payroll table
Id Period Net_pay
001 010105 5000
001 011605 300
001 030105 1000
001 040105 150
002 010105 1000
002 011505 500

I want the display like this if posible.. The first to character of the field period is the Month January to December.
Id January February March April ...........
001 5300 00 1000 150 ..........
002 1500 00 00 00 .............

Thank...You want a CROSSTAB query. Look it up in Books Online and you will get as good an explanation of how to do this as you could get on this forum.

Your only challenge should be converting the numeric string date format to the MonthName columns you want. You will need to do a CONVERT, CAST, or some other function, depending upon whether you have to worry about spanning years or not.|||Thanks Mr. Blindman for the reply...

No comments:

Post a Comment