ID  Name ShuLiang
1   上衣   3查询结果
ID  Name 
1   上衣   
1   上衣   
1   上衣   把数量改为查询的记录数量

解决方案 »

  1.   

    n=1
    while n<shuliang
    begin
    select id,name from table
    set n=n+1
    end提供个思路,具体自己去想吧
      

  2.   

    use Tempdb
    go
    --> --> 
     
    if not object_id(N'Tempdb..#T1') is null
    drop table #T1
    Go
    Create table #T1([ID] int,[Name] nvarchar(2),[ShuLiang] int)
    Insert #T1
    select 1,N'上衣',3
    Go
    Select a.[ID],a.Name
    from #T1 AS a
    INNER JOIN master.dbo.spt_values AS b ON b.type='P' AND b.number<a.[ShuLiang]
    /*
    ID Name
    1 上衣
    1 上衣
    1 上衣
    */
      

  3.   

    ID Name amount
    1 上衣 3
    查询结果
    ID Name  
    1 上衣   
    1 上衣   
    1 上衣 
    create table tbl(
    id int,
    name char(10),
    amount int
    )
    insert into tbl values(1,'上衣',3)
    ----------------------------------------
    declare @amount int
    set @amount=1
    create table #t(
    id int,
    name char(10)
    )
    while @amount<=(select amount from tbl)
    begin
    declare @id int,@name varchar(10)
    select @id=id,@name=name from tbl
    insert into #t values (@id,@name)
    set @amount=@amount+1
    end
    select *from #t
    ---------------
    id name
    1 上衣      
    1 上衣      
    1 上衣      
    ---------------
      

  4.   

    也可以这样:declare @amount int
    set @amount=1
    create table #f(
    id int,
    name char(10)
    )
    while @amount<=(select amount from tbl)
    begin
    declare @id int,@name varchar(10)
    --select @id=id,@name=name from tbl
    insert into #f select id,name from tbl--这个里有改变
    set @amount=@amount+1
    end
    select *from #f