Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Problem with query using CASE

Author  Topic 

ironmonkey
Starting Member

8 Posts

Posted - 2010-07-06 : 10:17:09
Not sure why i'm getting this error for the following query

Incorrect syntax near the keyword 'in'.


case @NumActualMonths
when @NumActualMonths in (10,11) then month(t.Level0_level_alias + ' 23 1983') <=12
when @NumActualMonths in (9,8,7) then month(t.Level0_level_alias + ' 23 1983') <=9
when @NumActualMonths in (6,5,4) then month(t.Level0_level_alias + ' 23 1983'} <=6
else month(t.Level0_level_alias + ' 23 1983') <=3
END

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-07-06 : 10:23:43
quote:
Originally posted by ironmonkey

Not sure why i'm getting this error for the following query

Incorrect syntax near the keyword 'in'.


case @NumActualMonths
when @NumActualMonths in (10,11) then month(t.Level0_level_alias + ' 23 1983') <=12
when @NumActualMonths in (9,8,7) then month(t.Level0_level_alias + ' 23 1983') <=9
when @NumActualMonths in (6,5,4) then month(t.Level0_level_alias + ' 23 1983'} <=6
else month(t.Level0_level_alias + ' 23 1983') <=3
END




N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-07-06 : 10:25:55
But you will get other errors later, because of the "less than or equal" to comparison.
Why don't you slow down and tell us what you have and what you want?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

ironmonkey
Starting Member

8 Posts

Posted - 2010-07-06 : 10:47:01
Hi Peso

I'm trying to do the following: I need a where clause that will do the following.

if @NumActualMonths = first column then delete all month records from second column. Where p3=1,2,3 (jan,feb,mar), p6(apr,may,jun)...etc

0 0
1 p3
2 p3
3 p3
4 p3,p6
5 p3,p6
6 p3,p6
7 p3,p6,p9
8 p3,p6,p9
9 p3,p6,p9
10 p3,p6,p9,p12
11 p3,p6,p9,p12

Sorry if I'm not very good at explaining this.

quote:
Originally posted by Peso

But you will get other errors later, because of the "less than or equal" to comparison.
Why don't you slow down and tell us what you have and what you want?


N 56°04'39.26"
E 12°55'05.63"


Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-07-06 : 10:58:22
[code]DELETE
FROM YourTableNameHere
WHERE YourColumnNameHere BETWEEN 0 AND (@NumActualMonths + 2) / 3 * 3[/code]The "YourColumnNameHere" is the column name holding the month value, ranging from 1 to 12.
If you have no column with month values, replace "YourColumnNameHere" with an expression calculating the month number.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

ironmonkey
Starting Member

8 Posts

Posted - 2010-07-06 : 12:28:13
Thanks Peso,

That worked for me!

Go to Top of Page
   

- Advertisement -