Marius Vasile

Marius Vasile

  • 591
  • 1.9k
  • 147.2k

Select from table not working

Oct 22 2024 1:00 PM

I am trying to get data from table with query below, basically trying to get int val from Value field for each month as V1, V2, etc

SELECT 
	(CASE When Month = 'January' Then Value Else 0 End) AS V1, 
	(CASE When Month = 'February' Then Value Else 0 End) AS V2, 
	(CASE When Month = 'March' Then Value Else 0 End) AS V3, 
	(CASE When Month = 'April' Then Value Else 0 End) AS V4, 
	(CASE When Month = 'May' Then Value Else 0 End) AS V5, 
	(CASE When Month = 'June' Then Value Else 0 End) AS V6, 
	(CASE When Month = 'July' Then Value Else 0 End) AS V7, 
	(CASE When Month = 'August' Then Value Else 0 End) AS V8, 
	(CASE When Month = 'September' Then Value Else 0 End) AS V9, 
	(CASE When Month = 'October' Then Value Else 0 End) AS V10, 
	(CASE When Month = 'November' Then Value Else 0 End) AS V11, 
	(CASE When Month = 'December' Then Value Else 0 End) AS V12

	FROM tblOmOra WHERE Year=@CurrentYear;

What is wrong with this query?


Answers (8)