SQL Server Forums
Profile | Register | 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
 find and replace
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kt
Yak Posting Veteran

80 Posts

Posted - 04/29/2013 :  14:01:48  Show Profile  Reply with Quote
Hi,

i have the string from the description like below. I want to find the first " and replace with empty.

"S40 12"" 316,316,17-4,RTFE/SI
i would like my final result shows below.
S40 12"" 316,316,17-4,RTFE/SI

thanks

James K
Flowing Fount of Yak Knowledge

3585 Posts

Posted - 04/29/2013 :  14:05:30  Show Profile  Reply with Quote
Use STUFF and PATINDEX functions like this:
DECLARE @x VARCHAR(255) = '"S40 12"" 316,316,17-4,RTFE/SI"'
SELECT STUFF(@x,PATINDEX('%"%',@x),1,'');
Go to Top of Page

kt
Yak Posting Veteran

80 Posts

Posted - 04/29/2013 :  14:24:34  Show Profile  Reply with Quote
you are sooooooooooo good, thank you very much.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3585 Posts

Posted - 04/29/2013 :  17:21:13  Show Profile  Reply with Quote
You are very welcome - glad to be of help.

One thing you do want to be careful about is if you have rows where there are no double-quotes at all. In such cases, you would get incorrect results, unless you check for it before doing the substituition.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 04/30/2013 :  04:40:33  Show Profile  Reply with Quote
this will make it still works for one without any " within it

DECLARE @x VARCHAR(255) = '"S40 12"" 316,316,17-4,RTFE/SI"'
SELECT STUFF(@x,PATINDEX('%"%',@x + '"'),1,'');



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.08 seconds. Powered By: Snitz Forums 2000