SQL查询:参数 [英] SQL Query : Parameters

查看:131
本文介绍了SQL查询:参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 
$


我在两个日期之间的每个月的第3个工作。每当工作运行时,它应该看起来3个月。 



所以我需要创建两个变量@begindate和@enddate



如果工作在2019年2月3日运行,那么@begindate应该是11/1/2018而@Enddate应该是1/31/2019。 

Hi, 

I run a job on 3rd of every month between two dates. Whenever the job runs, it should look 3 months back. 

So I need to create two variables @begindate and @enddate

If the Job runs On Feb 3rd, 2019, then the @begindate should be 11/1/2018 and @Enddate should be 1/31/2019. 

如果作业在3月31日运行,那么@begindate应该更改为  12/1/2018和@Enddate应该是2/28/2019。等等......
$


能否请你帮我...

If the Job runs On March 3rd, 2019, then the @begindate should change to  12/1/2018 and @Enddate should be 2/28/2019. and so on...

Could you please help me with this...

推荐答案

declare @rundate date='2019-02-03'
declare @begindate date, @enddate date 

Select @begindate =Dateadd(month,datediff(month,0,@rundate)-3,0)
,@enddate=EOMONTH(Dateadd(month,datediff(month,0,@rundate)-1,0))

Print  @begindate 
Print   @enddate





这篇关于SQL查询:参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆