双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

SQL语句是否可以在简单

look_007 look_007 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


declare @qz int,@wz int,@rq datetime,@bch char(4)

/*@qz 启始座位
@wz 结束座位
@rq 日期
@bch 班次号
*/
if @rq>=convert(char(10),getdate() ,102)
begin
declare @bj int
select @bj=patindex('%1%',substring(zw,@qz,@wz)) from zw where bch=@bch and bcrq=@rq
if @bj!=0
begin
select '存在售票,不予更改' as '提示' ,bch,zw from zw where bch=@bch and bcrq=@rq
return
end
else
begin
select '改之前' as '状态',bch,zw,bcrq,clbh from zw where bch=@bch and bcrq=@rq
select * from spqk where bch=@bch and bcrq=@rq
declare @ws int,@tj char(20)
declare @zs char(10),@sy char(10)
select @ws=len(zw) from zw where bch=@bch and bcrq=@rq
if @qz>@ws
begin
select @tj=@wz-@ws
update zw set zw=zw+replicate('3',@tj) where bch=@bch and bcrq=@rq
while @qz<=@wz
begin
update zw set zw=stuff(zw,@qz,1,'0') where bcrq=@rq and bch=@bch
select @qz=@qz+1
end
end
else
while @qz<=@wz
begin
update zw set zw=stuff(zw,@qz,1,'0') where bcrq=@rq and bch=@bch
select @qz=@qz+1
end
end
select @zs= (len(zw)-len(replace(zw,'0',''))+len(zw)-len(replace(zw,'1',''))) ,@sy=len(zw)-len(replace(zw,'0','')) from zw where bcrq=@rq and bch=@bch
update spqk set syps=@sy ,zsps=@zs where bch=@bch and bcrq=@rq
end
else
begin
print'日期不对,Today is '+convert(char(10),getdate(),102)
return
end

select '改之后' as '状态',bch,zw,bcrq,clbh from zw where bch=@bch and bcrq=@rq
----select '统计' as '统计', (len(zw)-len(replace(zw,'0',''))+len(zw)-len(replace(zw,'1',''))) as '准售',len(zw)-len(replace(zw,'0','')) as '剩余票',len(zw)-len(replace(zw,'1','')) as '已售' from zw where bch=@bch and bcrq=@rq
select * from spqk where bch=@bch and bcrq=@rq


各位高手,请问以上的代码是否可以在简单的。这样写虽然也能得到结果,但看起来很麻烦。
...全文
评论 3
收藏 已收藏
分享
返回顶部
look_007
MS-SQL Server 34,876 成员 254,635 内容