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 |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-04-09 : 15:00:09
|
| If I know a string variable has a special separator character in it. Is there a slick way to split the string into the two halves in SQL?e.g. can '12;abc' be split so 12 and abc are in separate varchar variables easily? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-04-09 : 15:04:01
|
| DECLARE @var1 VARCHAR(100)DECLARE @var2 VARCHAR(100)DECLARE @var3 VARCHAR(100)SET @var1 = '12;abc' SET @var2 = SUBSTRING(@var1, 1, PATINDEX('%;%', @var1) - 1)SET @var3 = SUBSTRING(@var1, PATINDEX('%;%', @var1) + 1, LEN(@var1))PRINT @var1PRINT @var2RPINT @var3Tara |
 |
|
|
|
|
|