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
 finding string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sent_sara
Constraint Violating Yak Guru

India
365 Posts

Posted - 06/17/2013 :  19:25:12  Show Profile  Reply with Quote
I need concantenate only those words until ":" from the starting point
(ie) output should be:
'New Member Territory "ADTest" :' and from the last only the rollup territory value
(ie) ' RollupTerritory "INT"'
so my final o/p should be: New Member Territory "ADTest" : RollupTerritory "INT"


declare @str nvarchar(max)
set @str='New Member Territory "ADTest" : Description "ANDORRA" : ParamountRegion "SOE" : Region "" : RegionDescription "SouthernEurope" : Country "A" : CountryDescription "Andor" : District "" : City "" : Area "" : TaxJurisdiction "" : Location "06" : RollupTerritory "INT"'
print @str

MuMu88
Aged Yak Warrior

547 Posts

Posted - 06/17/2013 :  20:07:31  Show Profile  Reply with Quote



declare @str nvarchar(max)
set @str='New Member Territory "ADTest" : Description "ANDORRA" : ParamountRegion "SOE" : Region "" : RegionDescription "SouthernEurope" : Country "A" : CountryDescription "Andor" : District "" : City "" : Area "" : TaxJurisdiction "" : Location "06" : RollupTerritory "INT"'
print @str
SELECT SUBSTRING(@str, 1, CHARINDEX( ':', @Str, 1)) +
	SUBSTRING(@str, (LEN(@Str) - CHARINDEX(':', REVERSE(@str), 1))+2, 1+CHARINDEX(':', REVERSE(@str), 1)) AS FINALSTRING;

Go to Top of Page

waterduck
Aged Yak Warrior

Malaysia
942 Posts

Posted - 06/17/2013 :  21:47:18  Show Profile  Reply with Quote
select left(@str, CHARINDEX( ':', @Str, 1)-1) +right(@str, CHARINDEX( ':', reverse(@Str), 1))
Go to Top of Page

MuMu88
Aged Yak Warrior

547 Posts

Posted - 06/17/2013 :  23:22:05  Show Profile  Reply with Quote
quote:
Originally posted by waterduck

select left(@str, CHARINDEX( ':', @Str, 1)-1) +right(@str, CHARINDEX( ':', reverse(@Str), 1))


Your query is much better. Thank you.
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.05 seconds. Powered By: Snitz Forums 2000