您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

sqlserver 存储过程中If Else的用法实例

2024/4/25 3:51:41发布6次查看
为大家介绍sql server存储过程中if esle的用法,供大家学习参考。数据库中有两张表,a表主键为自动增长的并且是b表的外键且允许为空 现在要通过编程向b表中插入数据,可是在程序中是不允许给int类型赋空值的如果不赋值就默认为0。 为了解决这个问题,用到了
为大家介绍sql server存储过程中if esle的用法,供大家学习参考。数据库中有两张表,a表主键为自动增长的并且是b表的外键且允许为空
现在要通过编程向b表中插入数据,,可是在程序中是不允许给int类型赋空值的如果不赋值就默认为0。
为了解决这个问题,用到了存储过程的if else,下面是完整的存储过程。
代码示例:
复制代码 代码如下:
create procedure [dbo].[p_form_control_info_add]
    @typename varchar(20),
    @description varchar(50),
    @ctlcolspan int,
    @sort int,
    @sourceid int,
    @fieldid int,
    @tableid int
as
if @sourceid = 0
begin
insert into t_form_control_info (
    [typename],
    [description],
    [ctlcolspan],
    [sort],
    [fieldid],
    [tableid]
) values (
    @typename,
    @description,
    @ctlcolspan,
    @sort,
    @fieldid,
    @tableid
)
end
else
begin
insert into t_form_control_info (
    [typename],
    [description],
    [ctlcolspan],
    [sort],
    [sourceid],
    [fieldid],
    [tableid]
) values (
    @typename,
    @description,
    @ctlcolspan,
    @sort,
    @sourceid,
    @fieldid,
    @tableid
)
end
return scope_identity()
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录