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 |
|
rahulmalhotra26
Starting Member
23 Posts |
Posted - 2008-02-03 : 20:25:29
|
| declare @sal char(50)DECLARE Employee_Cursor1 CURSOR static forSELECT salaryFROM test2OPEN Employee_Cursor1FETCH FROM Employee_Cursor1 into @salWHILE @@FETCH_STATUS = 0BEGIN FETCH NEXT FROM Employee_Cursor1 into @sal PRINT 'this is NOT the desired output which i wanted from so long :'+@sal ENDCLOSE Employee_Cursor1DEALLOCATE Employee_Cursor1Rahul |
|
|
rahulmalhotra26
Starting Member
23 Posts |
Posted - 2008-02-03 : 20:26:01
|
| THIS TABLE GIVES ME THIS OUTPUT20304040Rahul |
 |
|
|
rahulmalhotra26
Starting Member
23 Posts |
Posted - 2008-02-03 : 20:27:11
|
| THE TABLE I MADE TO TEST THIS IS HAVING ONLY ONE COLUMN SALARY WITH FOLLOWING ROWS10203040.. HOW CAN I GET THE OUTPUT AS 20,30,40AND WHY DOES IT REPEAT 40 TWO TIMES..Rahul |
 |
|
|
binilmb
Starting Member
2 Posts |
Posted - 2008-02-04 : 00:17:47
|
| Before the while loop ur fetching the record value to the variable...and also in the loop again ur fetching the record value before printing the fetched value....So give the fetch in the while loop after printing the first value... just like i mentioned belowdeclare @sal char(50)DECLARE Employee_Cursor1 CURSOR static forSELECT salaryFROM test2OPEN Employee_Cursor1FETCH FROM Employee_Cursor1 into @salWHILE @@FETCH_STATUS = 0BEGINPRINT 'this is NOT the desired output which i wanted from so long :'+@sal FETCH NEXT FROM Employee_Cursor1 into @salENDCLOSE Employee_Cursor1DEALLOCATE Employee_Cursor1Binil... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-04 : 01:30:42
|
| Declare @salary varchar(8000)select @salary=isnull(@salary+',','') from test2select @salaryBut better you do this concatenation at fron end applicationMadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|
|
|