当前位置: 移动技术网 > IT编程>数据库>MSSQL > sqlserver 存储过程中If Else的用法实例

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

恶龙军团优等生3,战皇全文阅读无弹窗,焦点 豆瓣

现在要通过编程向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()

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网