我想用EXEC语句重新写这条INSERT INTO ...... SELECT语句???
这是在一个存储过程里:
我想把这条插入语句用EXEC命令把其中的变量写活,CNWinImportantProject在(A数据库)和SystemInitialize在(B数据库)两张表是处于两个数据库中的表,其中@PrevDateTime,@NextDateTime,和@Type三个变量是存储过程传入的参数。
@PrevDateTime datetime,
@NextDateTime datetime,
@Type varchar(20)
请把下面这句Insert into ... select 语句用EXEC语句写出来
INSERT INTO CNWinImportantProject(
ProjectID,
ProjectStartDate,
ProjectEndDate,
ConferTotalCost,
CNWinTotalCost,
Type,
BelongMonth
)
select projectid,@PrevDateTime,@NextDateTime,0,0,@Type,0
from SystemInitialize
------解决方案--------------------declare @PrevDateTime datetime,
@NextDateTime datetime,
@Type varchar(20),
@sql varchar(8000)
select @sql= '
INSERT INTO CNWinImportantProject(
ProjectID,
ProjectStartDate,
ProjectEndDate,
ConferTotalCost,
CNWinTotalCost,
Type,
BelongMonth
)
select projectid, ' ' '+convert(char(19),@PrevDateTime,120)+ ' ' ', ' ' '+convert(char(19),@NextDateTime,120)+ ' ' ',0,0, ' ' '+@Type+ ' ' ',0
from SystemInitialize '