欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-10-26 20:00:28
--申明变量declare @ad_begin datetimedeclare @fydl varchar(50)declare @userid varchar(50)declare @jdrbm varchar(50) --变量赋值 set @ad_begin='2019-09-04'set @f ......

--申明变量
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;