怎样把以下的SQL,写成一条SQL:
declare @s nvarchar(4000)
set @s=''
if exists(select * from sysobjects where id=object_id(N'dbo.tj') and OBJECTPROPERTY(id,N'IsUserTable') = 1)
drop table dbo.tj
exec('select * into tj from OPENROWSET(''MICROSOFT.JET.OLEDB.4.0'',''Excel 8.0;IMEX=1;HDR=YES;DATABASE='+@excelfile+''',Sheet1$)')
select @s=@s+' union all select 年度='''+@Niandu+''',年级='''+@Glad+''',班级='''+@Class1+''',考试标志='''+@Tag+''',考试类型='''+@state+''',姓名,'''+a.name+''' as 科目,'+a.name+' as 分数 from tj' from syscolumns a,sysobjects b where a.id=b.id and b.xtype='U' and b.name='tj' and a.name<>'姓名' order by a.colid
select @s=stuff(@s,1,11,'')
begin tran
exec('insert into Student_CJ '+@s)
drop table dbo.tj
commit tran
declare @s nvarchar(4000)
set @s=''
if exists(select * from sysobjects where id=object_id(N'dbo.tj') and OBJECTPROPERTY(id,N'IsUserTable') = 1)
drop table dbo.tj
exec('select * into tj from OPENROWSET(''MICROSOFT.JET.OLEDB.4.0'',''Excel 8.0;IMEX=1;HDR=YES;DATABASE='+@excelfile+''',Sheet1$)')
select @s=@s+' union all select 年度='''+@Niandu+''',年级='''+@Glad+''',班级='''+@Class1+''',考试标志='''+@Tag+''',考试类型='''+@state+''',姓名,'''+a.name+''' as 科目,'+a.name+' as 分数 from tj' from syscolumns a,sysobjects b where a.id=b.id and b.xtype='U' and b.name='tj' and a.name<>'姓名' order by a.colid
select @s=stuff(@s,1,11,'')
begin tran
exec('insert into Student_CJ '+@s)
drop table dbo.tj
commit tran
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货