Sql Server中变的定义以及赋值的应用

–申明变量
declare @ad_begin datetime
declare @fydl varchar(50)
declare @userid varchar(50)
declare @jdrbm varchar(50)

–变量赋值

set @ad_begin=’2019-09-04′
set @fydl=’all’
set @userid=’0049′
set @jdrbm=’全部’

–sql中运用

select dbo.yw_hddz_yshdfygj.jsdwbm,dbo.yw_hddz_yshdfygj.jsdwmc,dbo.yw_hddz_yshdfygj.jsdwjc,
dbo.yw_hddz_yshdfygj.jsdwpym,dbo.yw_hddz_yshdfygj.jsbm,sum(dbo.yw_hddz_yshdfygj_cmd.fyje),0,’01’,’货代服务费用’,yw_hddz.jdrbm,dbo.yw_hddz.bm,0,0,”
from dbo.yw_hddz_yshdfygj,dbo.yw_hddz_yshdfygj_cmd ,dbo.yw_hddz
where dbo.yw_hddz_yshdfygj.yshdfygjbh = dbo.yw_hddz_yshdfygj_cmd.yshdfygjbh and
dbo.yw_hddz_yshdfygj_cmd.ywbh = dbo.yw_hddz.ywbh and
datediff(dd,gjsj,@ad_begin) >0 and (@fydl = ’01’ or @fydl = ’05’ or @fydl = ‘all’) and
isnull(khqr,’n’) <> ‘y’
and ( isnull(dbo.yw_hddz_yshdfygj_cmd.jdrbm,”) in (select dwbm from sys_user_dw where userid = @userid)) and (@jdrbm = ‘全部’ or @jdrbm = yw_hddz.jdrbm)
group by dbo.yw_hddz_yshdfygj.jsdwbm,dbo.yw_hddz_yshdfygj.jsdwmc,dbo.yw_hddz_yshdfygj.jsdwjc,
dbo.yw_hddz_yshdfygj.jsdwpym,dbo.yw_hddz_yshdfygj.jsbm,yw_hddz.jdrbm,dbo.yw_hddz.bm;

 

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐