首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 由于语法不熟悉,导致存储过程报错,大伙帮忙看看 [已结贴,结贴人:zbaii]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-20 20:31:01 楼主
    用在asp里的,但是不知道是否可以返回一些字符串变量会来,所以用return '字符串来写了'
    ==================
    create procedure draw
    as
    begin

    declare
    @itcode NVARCHAR(50),
    @id int

    select * from ticketLog where itcode = @itcode
    if @@ROWCOUNT = 0
      select top 1 @id=id from ticket where allSum>0 order by newid()
      if @@ROWCOUNT = 0
        return 'notTicket'//怎么返回异常呢?
      else
        update ticket set allSum=allSum-1 where id=@id
        insert into ticketLog (itcode,ticketID,dateTime) values(@itcode,@id,GETDATE())
        select * from ticket where id = @id //这里要返回成功后的票务信息
      end
    else
      return 'repeat'//怎么返回异常呢?
    end

    end
    ===============

    谢谢
    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-20 20:36:251楼 得分:20
    SQL code
    create procedure draw @err varchar(10) output as begin declare @itcode NVARCHAR(50), @id int select * from ticketLog where itcode = @itcode if @@ROWCOUNT = 0 select top 1 @id=id from ticket where allSum>0 order by newid() if @@ROWCOUNT = 0 begin set @err='notTicket' return (1) end else update ticket set allSum=allSum-1 where id=@id insert into ticketLog (itcode,ticketID,dateTime) values(@itcode,@id,GETDATE()) select * from ticket where id = @id //这里要返回成功后的票务信息 end else begin set @err='repeat' return (1) end end end go declare @err varchar(10) exec draw @err output select @err
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-20 20:39:212楼 得分:0
    return 只能是整数


    你可以
    return(1) 代表notTicket
    return(2) 代表repeat
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-20 20:39:223楼 得分:0
    服务器: 消息 156,级别 15,状态 1,过程 draw,行 23
    在关键字 'else' 附近有语法错误。
    服务器: 消息 156,级别 15,状态 1,过程 draw,行 28
    在关键字 'end' 附近有语法错误。
    服务器: 消息 2812,级别 16,状态 62,行 3
    未能找到存储过程 'draw'。

    (所影响的行数为 1 行)

    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-20 20:39:504楼 得分:0
    哥们,你在帮忙看看
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-20 20:53:345楼 得分:0
    逻辑比较混乱

    SQL里面,if语句块是多语句的要begin...end,你整理一下先,看不出你的逻辑


    if ??
    begin
      语句1
      语句1
      ...
    end

    else
    begin
      语句1
      语句1
      ...
    end
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-20 20:54:116楼 得分:0
    SQL code
    create procedure draw as begin declare @itcode NVARCHAR(50), @id int select * from ticketLog where itcode = @itcode if @@ROWCOUNT = 0 select top 1 @id=id from ticket where allSum>0 order by newid() if @@ROWCOUNT = 0 return 'notTicket'--//怎么返回异常呢? else begin--加上 update ticket set allSum=allSum-1 where id=@id insert into ticketLog (itcode,ticketID,dateTime) values(@itcode,@id,GETDATE()) select * from ticket where id = @id --//这里要返回成功后的票务信息 end else return 'repeat'--//怎么返回异常呢? end
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    世纪乐知(北京)网络技术有限公司 版权所有 京 ICP 证 020026 号
    Copyright © 2000-2007, CSDN.NET, All Rights Reserved