| Author |
Topic |
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-09-27 : 11:39:13
|
| hiI have in my setdata field 1 2 3 4 5. when i ran this:Declare @X as nvarchar(50), @loop int, @result as nvarchar(50)set @loop = 0Select @X = Count(setdata) from dbo.setdataWHILE @loop < @X BEGIN select @result = setdata from dbo.setdata print @result SET @Loop = @Loop + 1 END It print out 5 5 5 5 5. how do i make to printout 1 2 3 4 5? thanks |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2010-09-27 : 11:46:37
|
| While would you want to do this when:SELECT setdata FROM setdataWorks just fine? |
 |
|
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-09-27 : 11:53:26
|
| hiI want to use the variable for some other purpose. Thanks |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-09-27 : 12:06:06
|
quote: Originally posted by sg2255551 hiI have in my setdata field 1 2 3 4 5. when i ran this:Declare @X as nvarchar(50), @loop int, @result as nvarchar(50)set @loop = 0Select @X = Count(setdata) from dbo.setdataWHILE @loop < @X BEGIN select @result = setdata from dbo.setdata --There is no where condition for it to use @loop value. As a result it will assing one by one all values and the last value is getting stored in variable. print @result SET @Loop = @Loop + 1 END It print out 5 5 5 5 5. how do i make to printout 1 2 3 4 5? thanks
Regards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-09-27 : 12:12:18
|
| hiMy apology, how should i write the where condition in the while loop? thanks |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-09-27 : 12:22:48
|
quote: Originally posted by sg2255551 hiMy apology, how should i write the where condition in the while loop? thanks
If we know your requirement clearly then we can give better suggestion.With limited information given by you, I can only suggest:select @result = setdata from dbo.setdata where setdata = @loopprint @result |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-09-29 : 01:47:32
|
| hiThanks a lot. it is solved |
 |
|
|
|