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
 General SQL Server Forums
 New to SQL Server Programming
 Case statement with OR in in not working

Author  Topic 

robtop
Starting Member

9 Posts

Posted - 2011-09-19 : 04:23:45
Good Morning,

I've just started working with CASE statements and have found them extremely useful so far. However I've come accross a bit of an issue trying to put OR into one, see below

CASE WHEN dbo.Agent.AgentName = 'Abacus (Amalgamated)' OR 'Alan Blunden & Co Limited (Spectrum Abacus)' THEN 'ABACUS' ELSE AgentName END

I get the unable to parse expression error from this. It works if i just use one name but goes wrong as soon as i include the OR.

does anyone know what i'm doing wrong?

Thanks very much

Rob

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-09-19 : 04:38:56
Either:

CASE WHEN dbo.Agent.AgentName IN ('Abacus (Amalgamated)','Alan Blunden & Co Limited (Spectrum Abacus)') THEN 'ABACUS' ELSE AgentName END

or:

CASE WHEN dbo.Agent.AgentName = 'Abacus (Amalgamated)' OR dbo.Agent.AgentName = 'Alan Blunden & Co Limited (Spectrum Abacus)' THEN 'ABACUS' ELSE AgentName END


Go to Top of Page

robtop
Starting Member

9 Posts

Posted - 2011-09-19 : 04:46:48
Brilliant that works perfectly, thanks a lot
Go to Top of Page
   

- Advertisement -