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
 Column substring based on -

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2010-07-28 : 09:07:00
i need a query to trim the column value as below

QUERY
select Country from WorldTable
RESULT
Country Old-India_0001
Country-Japan_0002
Country New-China_0003

Need QUERY
select substring(Country,5 ,200) from WorldTable

Expected RESULT
India_0001
Japan_0002
China_0003


The trim should be based on -
the 5 should be replcaed dynaimcally by -
i am unable to form the substring
Kindly provide me the query


THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-07-28 : 09:08:45
give clarity to your post

With Regards
Kashyap M
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-28 : 09:13:27
select stuff(Country,1,patindex('%-%',Country),'')



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-28 : 09:22:23
Have you tried my solution?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2010-07-28 : 09:24:05
Thanks webfred !

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-28 : 09:26:34
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-28 : 09:29:22
or

select substring(Country,patindex('%-%',Country)+1,len(Country))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -