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
 Trouble with PATINDEX used in a CASE statement

Author  Topic 

snejsnej
Starting Member

9 Posts

Posted - 2013-09-06 : 14:40:58
Hi,

I have a number of columns I'm selecting from a table, and I'd like to use PATINDEX to search for a string within a field. Upon finding this string it would return another string...:


SELECT
CASE PARTNERID
WHEN PATINDEX('%INX%',PARTNERID)>0 THEN 'AXXENT'
ELSE PARTNERID
END AS PARTNERID


However, I'm getting this error:

Incorrect syntax near '>'.

Could someone please point me in the right direction?

Thanks
Jens

jethrow
Starting Member

37 Posts

Posted - 2013-09-06 : 14:47:07
[code]SELECT
CASE
WHEN PATINDEX('%INX%',PARTNERID)>0 THEN 'AXXENT'
ELSE PARTNERID
END AS PARTNERID[/code]

Microsoft SQL Server Noobie
Go to Top of Page

snejsnej
Starting Member

9 Posts

Posted - 2013-09-06 : 15:03:00
quote:
Originally posted by jethrow

SELECT
CASE
WHEN PATINDEX('%INX%',PARTNERID)>0 THEN 'AXXENT'
ELSE PARTNERID
END AS PARTNERID


Microsoft SQL Server Noobie



Yup, that did it, thanks. I have other CASE statements where I include the name of the column right after 'CASE', and they work fine. If you have a minute, can you explain why it didn't work here?
Thanks
Jens
Go to Top of Page

jethrow
Starting Member

37 Posts

Posted - 2013-09-06 : 15:22:30
I'd recommend looking this over: http://technet.microsoft.com/en-us/library/ms181765.aspx

Microsoft SQL Server Noobie
Go to Top of Page
   

- Advertisement -