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 2005 Forums
 Transact-SQL (2005)
 Case Statement in UDF

Author  Topic 

murrayb3024
Yak Posting Veteran

79 Posts

Posted - 2012-11-28 : 10:13:21
Trying to use a the following case statement in a user defined function but not working

SET @dd = CASE @aTotal
WHEN @aTotal IN (1,10,19,28,37,46,55,64,73,82,91) THEN 8
WHEN @aTotal IN (2,11,20,29,38,47,56,65,74,83,92) THEN 7
WHEN @aTotal IN (3,12,21,30,39,48,57,66,75,84,93) THEN 6
WHEN @aTotal IN (4,13,22,31,40,49,58,67,76,85,94) THEN 5
WHEN @aTotal IN (5,14,23,32,41,50,59,68,77,86,95) THEN 4
WHEN @aTotal IN (6,15,24,33,42,51,60,69,78,87,96) THEN 3
WHEN @aTotal IN (7,16,25,34,43,52,61,70,79,88,97) THEN 2
WHEN @aTotal IN (8,17,26,35,44,53,62,71,80,89,98) THEN 1
ELSE 0
END

Get this error: Incorrect syntax near the keyword 'IN'.

Can you not do an "IN" in a UDF?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-11-28 : 10:16:18
quote:
Originally posted by murrayb3024

Trying to use a the following case statement in a user defined function but not working

SET @dd = CASE @aTotal
WHEN @aTotal IN (1,10,19,28,37,46,55,64,73,82,91) THEN 8
WHEN @aTotal IN (2,11,20,29,38,47,56,65,74,83,92) THEN 7
WHEN @aTotal IN (3,12,21,30,39,48,57,66,75,84,93) THEN 6
WHEN @aTotal IN (4,13,22,31,40,49,58,67,76,85,94) THEN 5
WHEN @aTotal IN (5,14,23,32,41,50,59,68,77,86,95) THEN 4
WHEN @aTotal IN (6,15,24,33,42,51,60,69,78,87,96) THEN 3
WHEN @aTotal IN (7,16,25,34,43,52,61,70,79,88,97) THEN 2
WHEN @aTotal IN (8,17,26,35,44,53,62,71,80,89,98) THEN 1
ELSE 0
END

Get this error: Incorrect syntax near the keyword 'IN'.

Can you not do an "IN" in a UDF?




Too old to Rock'n'Roll too young to die.
Go to Top of Page

murrayb3024
Yak Posting Veteran

79 Posts

Posted - 2012-11-28 : 10:20:11
wow, totally missed that, thank you.
Go to Top of Page
   

- Advertisement -