用户登录
用户注册

分享至

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

  • 作者: 旧人不覆48083924
  • 来源: 51数据库
  • 2021-09-05

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

 

软件
前端设计
程序设计
Java相关