Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 2nd, 2006, 01:34 PM
dp111 dp111 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 dp111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 5 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old May 7th, 2006, 08:51 AM
som_dutt som_dutt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 12 som_dutt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m 5 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old May 9th, 2006, 10:42 AM
dp111 dp111 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 dp111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 5 sec
Reputation Power: 0
Thanks a lot Som! Dan

Thank you Som!

Dan


Quote:
Originally Posted by som_dutt
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Output


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT