|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Output
Hi:
I have this table: ID MI1 MI2 QTY 123 1007 1005 2 so based on QTY, I want the output: 123 1007 1005 123 1007 1005 if the qty is 3(variable) or others: 123 1007 1005 123 1007 1005 123 1007 1005 etc What would be the syntax, declare fetch cursor, loop, etc. Thanks, D |
|
#2
|
|||
|
|||
|
Hi dp!
I'm not sure whether you want a stored procedure or a function for this. The problem you have put, can find solution in following statement. I am creating procedure - ----------------------------------------------------------------------------------- Create proc pr_001 as declare @cnt int declare @x int select @cnt=qty from table1 set @x = @cnt while (@x !=0) begin if ( @x = @cnt) select ID, MI1, MI2 into #tmps from table1 else insert into #tmps select ID, MI1, MI2 from table1 set @x = @x - 1 end select * from #tmps GO ----------------------------------------------------------------------------------- (The same can be done in serveral other ways.) Based on the same concept you can even create a function that would return a table as RETURNS. If this doesn't help tell us the scenario in detail. - Som Dutt |
|
#3
|
|||
|
|||
|
Thanks a lot Som! Dan
Thank you Som!
Dan Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Output |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|