我将多个插入查询合并到一个查询中(比如combine1.sql
)
--insert query 1
--insert query 2
.
.
.
Declare @Tbl_Id INT
Select @Tbl_Id = Id from students where Code='123'
--null value comes in @Tbl_Id
insert into mappingtable values(@Tbl_Id, getdate())
.
.
.
--insert query n
当我执行@Tbl_Id
时,我在combine1.sql
中获得空值,
但是,当我执行
Declare @Tbl_Id INT
Select @Tbl_Id = Id from students where Code='123'
--5 comes in @Tbl_Id
insert into mappingtable values(@Tbl_Id, getdate())
combine1.sql
可能出现的问题。任何帮助表示赞赏。
答案 0 :(得分:0)
像这样检查@Tbl_Id值的一件事
Declare @Tbl_Id INT
Select @Tbl_Id = Id from students where Code='123'
--5 comes in @Tbl_Id
if(@Tbl_Id is not null)
begin
insert into mappingtable values(@Tbl_Id, getdate())
end