日期:2014-05-18 浏览次数:21117 次
declare @Sql nvarchar(500) declare @SysOrderNo int declare @ShortName varchar(30),@Spec varchar(30),@Spec1 varchar(30),@Spec2 varchar(30),@Spec3 varchar(30),@Spec4 varchar(30) declare @DataBaseName varchar(30) Set @DataBaseName='MDFData' Set @SysOrderNo=5 Set @Sql='Select @ShortName=ShortName,@Spec=Spec,@Spec1=Spec1,@Spec2=Spec2,@Spec3=Spec3,@Spec4=Spec4 From '+@DataBaseName+'.dbo.ORDERDETAIL '+' Where SysOrderNo='+cast(@SysOrderNo as varchar(10)) Select @Sql exec sp_executesql @Sql,N'@ShortName varchar(30) output,@Spec varchar(30) output,@Spec1 varchar(30) output,@Spec2 varchar(30) output,@Spec3 varchar(30) output,@Spec4 varchar(30) output',@ShortName output,@Spec output,@Spec1 output,@Spec2 output,@Spec3 output,@Spec4 output Select @ShortName,@Spec,@Spec1,@Spec2,@Spec3,@Spec4
declare @Sql nvarchar(500) declare @SysOrderNo int declare @ShortName varchar(30),@Spec varchar(30),@Spec1 varchar(30),@Spec2 varchar(30),@Spec3 varchar(30),@Spec4 varchar(30) declare @DataBaseName varchar(30) Set @DataBaseName='MDFData' Set @SysOrderNo=5 create table #T ( Row int identity(1,1) not null, ShortName varchar(30) null, Spec varchar(30) null, Spec1 varchar(30) null, Spec2 varchar(30) null, Spec3 varchar(30) null, Spec4 varchar(30) null, primary key (Row) ) DECLARE @Rows int, @Row int Set @Sql=' insert into #t Select ShortName,Spec,Spec1,Spec2,Spec3,Spec4 From '+@DataBaseName+'.dbo.ORDERDETAIL '+' Where SysOrderNo='+cast(@SysOrderNo as varchar(10)) exec sp_executesql @Sql set @Rows = @@ROWCOUNT set @Row = 1 while (@Row<=@Rows) begin Select @ShortName = ShortName,@Spec = Spec,@Spec1 = Spec1,@Spec2 = Spec2, @Spec3 = Spec3,@Spec4 = Spec4 from #T where Row = @Row select @ShortName,@Spec,@Spec1,@Spec2,@Spec3,@Spec4 set @Row = @Row + 1 end