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 |
|
ismailc
Constraint Violating Yak Guru
290 Posts |
Posted - 2010-01-17 : 05:08:56
|
| Hi, I got the split function working together with getting the first row value.This works fine but it does work on getting the first row value when there is no "," in value to split then i get error incorrect parameter.set @Firstval = substring(@str,1,charindex(',',@str)-1) declare @str varchar(100) set @str = (select User from dbo.fcUser where username = 'test') declare @firstval varchar(100) set @Firstval = substring(@str,1,charindex(',',@str)-1) select @Firstval as DefaultUserPlease help |
|
|
ismailc
Constraint Violating Yak Guru
290 Posts |
Posted - 2010-01-17 : 05:55:40
|
| got help :)declare @str varchar(100) SET @str = 'Test'declare @firstval varchar(100)DECLARE @pos int;SET @pos = charindex(',',@str)IF @pos = 0 SET @pos = LEN(@str) + 1set @Firstval = substring(@str,1,@pos - 1) select @Firstval as DefaultUser |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-01-18 : 02:37:38
|
| <<set @str = (select User from dbo.fcUser where username = 'test') >>Note that if the query returns more than a value, it would throw errorMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|