日期:2014-05-18  浏览次数:20459 次

初学者,求一存储过程,正解后即结贴!
有两个表,talbe1(a,b,c),tabe2(a,d,e),(a,b,c,d,e)都表示表中字段.
有一个变量@q,当变量为空时,在两个表(tabel1,tabel2)中都插入数据,当变量不为空是,仅在一个表中插入数据table2.
对存储过程刚刚起步,请各位大侠帮帮忙!因于水平很差,大家最好给出实例.不甚感激!

------解决方案--------------------
declare @q int
if @q is null
begin
insert into table1...
insert into table2...
end
else
begin
insert into table2...
end

------解决方案--------------------
create table T1(a int, b int, c int)
create table T2(a int, d int, e int)

create proc pc
@a int,
@b int,
@c int,
@d int,
@e int,
@q int
as
if @q is null
begin
insert T1 values(@a, @b, @c)
insert T2 values(@a, @d, @e)
end
else
begin
insert T2 values(@a, @d, @e)
end