当前位置: 代码迷 >> Sql Server >> 小弟我想用EXEC语句重新写这条INSERT INTO . SELECT语句?
  详细解决方案

小弟我想用EXEC语句重新写这条INSERT INTO . SELECT语句?

热度:59   发布时间:2016-04-27 19:02:30.0
我想用EXEC语句重新写这条INSERT INTO ...... SELECT语句???
这是在一个存储过程里:
我想把这条插入语句用EXEC命令把其中的变量写活,CNWinImportantProject在(A数据库)和SystemInitialize在(B数据库)两张表是处于两个数据库中的表,[email protected],@NextDateTime,[email protected]

@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, ' ' '[email protected]+ ' ' ',0
from SystemInitialize '
  相关解决方案