sqlserver2008存储过程输入参数简单例子讲解?

解决方案 »

  1.   


    CREATE PROC test_inputproc
    @input int
    AS
    BEGIN
    IF @input=1
    PRINT '@input='+CAST(@input AS VARCHAR(10))
    ELSE 
    PRINT '@input<>1'
    ENDEXEC test_inputproc 1
    EXEC test_inputproc 2
    [code]
    @input=1
    @input<>1
    [/code]
      

  2.   


    create procedure test_proc              --创建存储过程 test_proc
    @dept varchar(10)                       --输入参数@dept
    as
    begin                                   --语句开始
    select * from test4 where dept=@dept    -- 查询test4表中dept=输入参数@dept的所有记录
    end                                      --语句结束
    --------------------------------------------------------
    exec test_proc '行政部'                 --执行存储过程 test_proc 输入参数为 行政部
    ----结果--------------------------------------------------
    id          dept       date
    ----------- ---------- -----------------------
    2           行政部        2014-07-18 15:16:35.540
    3           行政部        2014-08-03 14:04:15.580
    38          行政部        2014-07-10 20:06:35.340
    40          行政部        2014-08-20 09:04:18.410
    46          行政部        2014-08-27 14:13:01.230
    52          行政部        2014-08-20 09:04:18.410
    59          行政部        2014-08-27 14:13:19.833(7 行受影响)
      

  3.   


    CREATE PROCEDURE protest
    @input int
    AS
    BEGIN
    set @input= @input +1
    SELECT @input
    END
    GO
    exec   protest  1结果是2