将查询结果转化为值插入另一张表的字段中(急)
例如将,
select top 1 ID from C31VesselInfo的结果插入到另一张表中
目前这样写是语法错误的,麻烦纠正下,谢谢了
insert into C31VisaInfo(ID,IssuanceDate,ExpirationDate,Status,VesselID)
values ('18','2014-1-1','2014-1-1','有效',
VALUE(select top 1 ID from C31VesselInfo where VesselName = '瑞安0018'))
------解决方案--------------------insert into C31VisaInfo(ID,IssuanceDate,ExpirationDate,Status,VesselID)
select top 1 '18','2014-1-1','2014-1-1','有效',ID from C31VesselInfo where VesselName = '瑞安0018'
------解决方案--------------------insert into C31VisaInfo(ID,IssuanceDate,ExpirationDate,Status,VesselID)
values ('18','2014-1-1','2014-1-1','有效',(select top 1 ID from C31VesselInfo where VesselName = '瑞安0018'))
------解决方案--------------------建议用as来明确select中的列名对应insert中的哪个列
insert into C31VisaInfo(ID,IssuanceDate,ExpirationDate,Status,VesselID)
select top 1 '18','2014-1-1','2014-1-1','有效', ID, from C31VesselInfo where VesselName = '瑞安0018'
------解决方案--------------------大神们都写出来了,我也就不写了
你如果经常用 T-SQL查询,推荐看看MICROSOFT SQL SERVER 2008技术内幕:T-SQL语言基础
你这个贴的需求在第八章可以解决 数据修改..
另外给你个下载链接 http://bbs.csdn.net/topics/390719238
百度云转存即可