views:

8

answers:

1

Hello,

What is the right syntax for this query in MS-SQL 2005?

select case app.NAMED_USER
 WHEN app.NAMED_USER > 50 AND app.NAMED_USER <=0 THEN 4 
 WHEN app.NAMED_USER > 500 THEN 9
 WHEN app.NAMED_USER > 500O THEN 12 
FROM APPLICATION app
 WHERE  app.NAME LIKE '%application 5%'

i get a error message below, which I can not decipher.. I presume, it involves the variable type or the syntax to use with operands.

I hope someone can help.

Greetings,

hein

A: 

I'd do it like this:

select 
 case 
  WHEN app.NAMED_USER > 50 AND app.NAMED_USER <=0 THEN 4  
  WHEN app.NAMED_USER > 500 THEN 9 
  WHEN app.NAMED_USER > 5000 THEN 12  
 end
FROM APPLICATION app 
 WHERE  app.NAME LIKE '%application 5%'

Among other things, app.NAMED_USER can never be less than equal 0 and also greater than 50.

Jono
Thanks. I discovered this morning I had not distinguished between the case statement's searched and calculated mode. Greetings, Hein