zoukankan      html  css  js  c++  java
  • 20151015存储过程

    --定义变量
    declare @a int
    --变量赋值
    set @a =12
    --显示变量
    print @a


    --累加求和
    declare @a int,@sum int ,@i int
    set @a=10 set @sum=0 set @i=1
    while @i<=@a
    begin
    set @sum=@sum+@i
    set @i=@i+1
    end
    print @sum


    declare @pingguo varchar(10)
    select @pingguo=price from fruit where ids='k001'
    select *From fruit where price != @pingguo

    --存储过程
    create proc leijia
    @a int
    as
    declare @sum int ,@i int
    set @sum=0 set @i=1
    while @i<=@a
    begin
    set @sum=@sum+@i
    set @i=@i+1
    end
    return @sum
    go

    --接受
    declare @sum int
    exec @sum=leijia 10
    print @sum


    --一元二次方程

    drop proc yiyuanerci

    create proc yiyuanerci
    @a decimal,@b decimal,@c decimal
    as
    declare @daierta decimal,@panduan int
    set @daierta=@b*@b-(4*@a*@c)
    set @panduan=0
    if @a=0
    begin
    set @panduan=-1
    end

    else
    begin
    if @daierta<0
    begin
    set @panduan=0
    end
    if @daierta=0
    begin
    set @panduan=1
    end
    if @daierta>0
    begin
    set @panduan=2
    end
    end
    return @panduan
    go

    declare @jieguo int
    exec @jieguo=yiyuanerci 0,2,3
    if @jieguo=-1
    begin
    print '不是一元二次'
    end
    if @jieguo=0
    begin
    print '没有实数跟'
    end
    if @jieguo=1
    begin
    print '两个相等的实数跟'
    end
    if @jieguo=2
    begin
    print '两个不想等的实数跟'
    end


    --有结果的一元二次方程
    drop proc aaaa

    create proc aaaa
    @a decimal,@b decimal,@c decimal,@jieguo1 decimal out,@jieguo2 decimal out
    as
    declare @panduan int
    set @panduan=0
    if @a=0
    begin
    set @panduan=-1
    end

    else
    begin
    declare @daierta decimal
    set @daierta=@b*@b-(4*@a*@c)
    set @jieguo1=(-@b- SQRT(@daierta) ) / (2 * @a)
    set @jieguo2=(-@b+ SQRT(@daierta) ) / (2 * @a)
    if @daierta<0
    begin
    set @panduan=0
    end
    if @daierta=0
    begin
    set @panduan=1
    end
    if @daierta>0
    begin
    set @panduan=2
    end
    end
    return @panduan

    go


    declare @jieguo int,@x1 decimal,@x2 decimal
    exec @jieguo=aaaa 0,5,2,@x1 out,@x2 out
    if @jieguo=-1
    begin
    print '不是一元二次'
    end

    if @jieguo=0
    begin
    print '没有实数跟'
    end

    if @jieguo=1
    begin
    print '两个相等的实数跟,为'print @x1
    end
    if @jieguo=2
    begin
    print '两个不想等的实数跟'print @x1 print @x2
    end

    select *from fruit
    drop proc shuiguo
    --水果进货表
    create proc shuiguo
    @ids varchar(20),@Name varchar(20),@price decimal,@source varchar(20),@stack int ,@numbers int ,@image varchar(20)
    as
    --进货
    if @numbers>0
    begin
    declare @count int
    select @count =COUNT(*) from fruit as a where a.ids=@ids
    if @count>0
    begin
    update fruit set numbers=@numbers+numbers where ids=@ids
    return 2
    end
    else
    begin
    insert into fruit values (@ids,@name,@price,@source,@stack,@numbers,@image)
    return 1
    end
    end
    --出货
    else
    begin
    declare @shuliang int
    select @shuliang=numbers from fruit where ids=@ids
    if @shuliang>@numbers
    begin
    update fruit set numbers=@numbers+numbers where ids=@ids
    return 1
    end
    else
    begin
    return -2
    end
    end

    go

    select *from fruit
    --
    declare @fanhui int
    exec @fanhui = shuiguo 'k008','香梨',5.1,'库尔勒',4,-10,'image/7.gif'
    if @fanhui=-2
    begin
    print '不够出货'
    end

  • 相关阅读:
    div常用设置
    Chrome-Charset——Chrome最新版右键工具中的编码修改功能没有了的解决工具
    PHP数据访问(面向对象方式:mysqli类)
    JSON
    jQuery
    jQuery事件
    会话保持
    查询的例子,房屋租赁
    PHP CRUD
    批量删除
  • 原文地址:https://www.cnblogs.com/hz1234/p/4941195.html
Copyright © 2011-2022 走看看