首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

菜鸟,求一存储过程,正解后即结贴

2012-01-18 
初学者,求一存储过程,正解后即结贴!有两个表,talbe1(a,b,c),tabe2(a,d,e),(a,b,c,d,e)都表示表中字段.有一

初学者,求一存储过程,正解后即结贴!
有两个表,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

热点排行