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
 Using Charindex

Author  Topic 

Petronas
Posting Yak Master

134 Posts

Posted - 2012-03-26 : 16:11:15
Hi,

I have the following field :


Partner
TURNERCX&QAS=Y
5291MCCAULTH&QAS=Y
3230&QAS=Y


I need to get only the part of the string in red.
Current Code:
case when Partner like '%&QAS%' then

SUBSTRING(Partner, CHARINDEX('',Partner), 10)

Thanks for your help,
Petronas

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-03-26 : 17:24:34
[code]SELECT LEFT(Partner, charindex('&', Partner)-1)
FROM YourTable[/code]
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-03-26 : 17:26:21
Or, if you need to test for the existence of the ampersand 1st...
SELECT	Case WHEN charindex('&', partner) = 0 THEN Partner
ELSE
LEFT(Partner, charindex('&', Partner)-1)
End
FROM YourTable
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-27 : 12:33:09
SELECT STUFF(Partner, charindex('&', Partner),LEN(Partner),'')
FROM YourTable


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-27 : 12:55:02
SELECT REPLACE([Partner],'&QAS=Y','')

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -