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.
Author |
Topic |
Monhana
Starting Member
5 Posts |
Posted - 2013-08-12 : 17:43:26
|
Hi,I have fields Country and State that has value:Rockingham, NHVermilion, LACan you please help me out with stripe Country Vermilion (without comma) and state is LACountry: RockinghamState: NHThanks |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-08-12 : 18:14:59
|
[code] SELECT LEFT(YourColumn, CHARINDEX(',',YourColumn+',')-1) AS County, STUFF(YourColumn,1,CHARINDEX(',',YourColumn+','),'') AS STATEFROM YourTable;[/code] |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-08-13 : 00:40:42
|
if you have only 2 characters in the STATE Code column, you can query as follwsSELECT LEFT( ColumnName, CHARINDEX(',', ColumnName+',')-1) AS Country, RIGHT( ColumnName, 2)FROM TableName; --Chandu |
|
|
Monhana
Starting Member
5 Posts |
Posted - 2013-08-20 : 14:07:16
|
Thank you very much for your time to reply. It works and I got output that expected. |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-08-21 : 00:55:57
|
quote: Originally posted by Monhana Thank you very much for your time to reply. It works and I got output that expected.
welcome--Chandu |
|
|
|
|
|
|
|