insert into table select * from temp_table
这个语法中,insert 和 select 都亩册写清楚列简碧名迅咐宏:
insert into table(col1,col2,...) select col1,col2,... from temp_table使用SP实现,存储过程设置参数,列名和需要添加的 字段名称
执行SP前表为:
执行SO后为 : exec addProductDate @table='table_1',@colName='product_date'
SP 代码为
create procedure addProductDate
@table nvarchar(100),
@colName nvarchar(100)
as
declare @sql nvarchar(500)
if not exists(select name from syscolumns where id=(select id from sysobjects where name=@table) and name=@colName)
begin
set @sql ='alter table '+@table+' add '+ @colName+' smalldatetime'
execute(@sql)
END
set @sql='update '+@table+' set '+@colName+' =Convert(varchar(100),left(InsertTime,10)+'+''' 17:30:00'''+',25) where WorkShiftName='+'''早班'''+ ''亏迅携+
'update '+@table+' set '+@colName+' =Convert(varchar(100),left(InsertTime,10)+'+''' 20:30:00'''+',25) where WorkShiftName='销伏+'''晚班'''+ ' and right(InsertTime,11)='+'''19:31-23:59'''+' '+
'update '+@table+' set '+@colName+' =dateadd(dd,-1,Convert(varchar(100),left(InsertTime,10)+'+''' 20:30:00''昌渣'+',25)) where WorkShiftName='+'''晚班'''+' and right(InsertTime,11)='+'''00:00-07:28'''+' '
execute(@sql)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)