| Author |
Topic |
|
satish.gorijala
Posting Yak Master
182 Posts |
Posted - 2010-03-17 : 06:41:50
|
| Hi, i have below piece of code.Declare @i intset @i = 96While(@i < 100)Begin set @i = @i +1 Select 'sat' + char(@i)EndI am getting output as satasatbsatcsatdInstead of this, i am looking for output assatabcdI tried this way..but now luckDeclare @i intDeclare @finalstr varchar(30)set @i = 96While(@i < 100)Begin set @i = @i +1 Set @finalstr = @finalstr + 'sat' + char(@i)EndSelect @finalstr what change i need to do in my code?developer :) |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-03-17 : 06:49:00
|
Almsot there:Declare @i intDeclare @finalstr varchar(30)SET @finalStr = 'sat'set @i = 96While(@i < 100)Beginset @i = @i +1Set @finalstr = @finalstr + char(@i)EndSelect @finalstr Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-17 : 06:49:55
|
[code]select @finalstr = isnull(@finalstr, 'sat') + char(@i)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-17 : 06:50:22
|
 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
satish.gorijala
Posting Yak Master
182 Posts |
Posted - 2010-03-17 : 07:00:12
|
Its fine. If there is no intial data to append..How can i do? I mean..how the following code to be execute.. I am getting NULL value as outputDeclare @i intDeclare @finalstr varchar(30)set @i = 96While(@i < 100)Begin set @i = @i +1 Set @finalstr = @finalstr + char(@i)EndSelect @finalstrquote: Originally posted by Transact Charlie Almsot there:Declare @i intDeclare @finalstr varchar(30)SET @finalStr = 'sat'set @i = 96While(@i < 100)Beginset @i = @i +1Set @finalstr = @finalstr + char(@i)EndSelect @finalstr Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
developer :) |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-03-17 : 07:10:17
|
| Huh?Either use khatan's suggestion or mine.My way initialises the variable first before the loop with a value (could be the empty string if you wanted. Khatan's checks for a null in every loop and substitutes for a value.If you add anything to NULL you get NULL.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-03-17 : 07:10:58
|
| "Set @finalstr = @finalstr + char(@i)"You are concatenating char(@i) to NULL (value of @finalstr) because you haven't initialised @finalstr, nor used IsNull - both suiggested in the replies above |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-17 : 07:11:29
|
[code]select @finalstr = isnull(@finalstr, '') + char(@i)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
satish.gorijala
Posting Yak Master
182 Posts |
Posted - 2010-03-17 : 07:15:20
|
| Thank you Charliedeveloper :) |
 |
|
|
|