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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trouble with PATINDEX used in a CASE statement
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

snejsnej
Starting Member

9 Posts

Posted - 09/06/2013 :  14:40:58  Show Profile  Reply with Quote
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

USA
37 Posts

Posted - 09/06/2013 :  14:47:07  Show Profile  Reply with Quote
SELECT
	CASE
	WHEN PATINDEX('%INX%',PARTNERID)>0 THEN 'AXXENT'
	ELSE PARTNERID 
	END AS PARTNERID


Microsoft SQL Server Noobie
Go to Top of Page

snejsnej
Starting Member

9 Posts

Posted - 09/06/2013 :  15:03:00  Show Profile  Reply with Quote
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

USA
37 Posts

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

Microsoft SQL Server Noobie
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000