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;
- SQLite数据库操作:原生操作,GreenDao操作讲解
- 数据库SQL实战题:获取员工其当前的薪水比其manager当前薪水还高的相关信息(教程)
- SQLSERVER查询区分大小写的写法分析
- SQL学习总结之SQL的分类介绍
- 阶梯到高级T-SQL 1级:高级T-SQL介绍交叉连接
- 高级T-SQL级别1的Stairway:使用CROSS JOIN引入高级T-SQL分析
- 什么是SQL隔离级别?四个SQL隔离级别定义介绍
- Sql递归介绍之用with实现递归查询
- SQLSERVER查询时日期格式化的实例讲解
- 数据库SQL实战:从titles表获取按照title进行分组,注意对于重复的emp_no进行忽略(题解)