December 18, 2009 at 12:01 am
Hi,
I want to remove the Leading and trailing double-double-quotes("") and replaced with a double-quote (")
Example: ""description"" needs to look like "description"
And Embedded double-double-quotes ("") and doube-quotes (") should be left alone.
Example: desc""ription should still end up as desc""ription(same for double-quotes (").
The following query is workig fine for me:
declare @des varchar(80)
select @des = '""desc""ripti""on""'
select @des = case when left(@des, 2) = '""' then right(@des,len(@des)- 1) else @des end
select @des = case when right(@des, 2) = '""' then left(@des,len(@des)- 1) else @des end
print @des
but the query is not working for the string ''""""desc""ripti""on""''
declare @des varchar(80)
select @des = '""""desc""ripti""on""'
select @des = case when left(@des, 2) = '""' then right(@des,len(@des)- 1) else @des end
select @des = case when right(@des, 2) = '""' then left(@des,len(@des)- 1) else @des end
print @des
Please give me the solution for remove only the leading and trailing double-double qoutes and make it as single double quotes.
December 18, 2009 at 12:24 am
Sorry if I've misunderstood ur requirement, but is this what you need?
(this is what I could think of using STUFF, there could be better ways!)
declare @des varchar(80)
select @des = '""desc""ripti""on""'--'""descr""iption""'
PRINT REVERSE(STUFF(REVERSE(STUFF(@des,1,2,'"')),1,2,'"'))
PRINT STUFF(STUFF(@des,1,2,'"'),len(@des)-2,2,'"')
---------------------------------------------------------------------------------
December 18, 2009 at 12:43 am
Thanks for ur reply.
It will work for the below string
eg: select @des = '""desc""ripti""on""'
could you please check with the following string
eg: select @des = '""""desc""ripti""on""'
December 18, 2009 at 1:02 am
Hi,
Try this
declare @des varchar(80)
select @des = '""desc""ripti""on""'
select @des
--select PATINDEX('%[A-Z]%',@des)
--select len(@des)-1-PATINDEX('%[A-Z]%',reverse(@des))
select '"'+substring(@des,PATINDEX('%[A-Z]%',@des),(len(@des)-1-PATINDEX('%[A-Z]%',reverse(@des))))+'"'
December 18, 2009 at 2:52 am
Hi,
Thanks for your help. Its working fine.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply