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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Problem of strings

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-06-23 : 10:39:18
Mr Y writes "Version SQL 8.00.194

Set @tmp='DSMC020S021~200'

I want to store the above data in two variables as
@t1='DSMC020S021'
@t2='200'

Excluding ~

Please find me a solution"

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-06-23 : 10:42:43
select @t1 = SUBSTRING(@tmp, 1, CHARINDEX('~', @tmp) - 1),
@t2 = SUBSTRING(@tmp, CHARINDEX('~', @tmp) + 1, 20)

Be aware that this assumes @tmp always contains ~. You should code for the variable not having this sometimes by checking CHARINDEX is non zero first.


Raymond
Go to Top of Page
   

- Advertisement -