Sql server SQL Where子句中具有不同值的日期数组

Sql server SQL Where子句中具有不同值的日期数组,sql-server,where,Sql Server,Where,我需要从问题表中获取所有的valuesLeft联接,其中包括t 声明表中的日期。 但不知何故,我只能在满足以下条件的情况下提取记录: Q.Author_ID = S.Author_id 为了在发送日期前4周的数据中提供所有结果,我在查询中做了哪些更改 SQL查询 你的问题回答表在哪里?请把它的模式也贴出来。我没有模式,但我的结果是主题“作者id 11500310 11292137 13171508 59685895 13224725 10263656 13277539 59685895 132

我需要从问题表中获取所有的valuesLeft联接,其中包括t 声明表中的日期。 但不知何故,我只能在满足以下条件的情况下提取记录:

Q.Author_ID = S.Author_id
为了在发送日期前4周的数据中提供所有结果,我在查询中做了哪些更改

SQL查询


你的问题回答表在哪里?请把它的模式也贴出来。我没有模式,但我的结果是主题“作者id 11500310 11292137 13171508 59685895 13224725 10263656 13277539 59685895 13282148 11292137 13299872 59685895 13301051 59685851 13302671 59685895 13303432 59685895 13303565 59685895 13305230 59685895我需要在author\u id column中输入一些空值,因为左联接的作用是这样的。您能否解释一下,我如何使用where子句从我声明的表中只选择sent\u date列中的日期。@user3156213如果您只想从sent\u date列use in子句中选择日期,比如从tablename中选择sent_date中的Where date,但我没有得到您的要求,我不知道left Join是否会正确响应此条件,但请尝试一下。我的要求是我希望我的查询给出sent_date和fixed date列的日期范围的结果。@user3156213我没有您的第二个表信息,但如果这对你有帮助,
Declare @Sample_Alankar Table
(
 Author_id int,
 Sent_date Datetime,
 Fixed_Date datetime
)
Declare @StartDate DateTime
Declare @EndDate DateTime
Declare @NumofWeeks Int

Set @NumofWeeks = 4 -- change this to the number of days you are interested in...say pros responding to atleast one question in last "60" days
Set @StartDate = '7/1/2013'
Set @EndDate =  '9/1/2013'

insert @Sample_Alankar values 
(63977546,'11/5/2013','11/13/2013'),
(61534878,'11/5/2013','11/13/2013'),
(59725966,'11/4/2013','11/13/2013'),
(30945867,'9/18/2013','9/25/2013'),
(10263656,'11/4/2013','11/13/2013'),
(59685895,'9/3/2013','9/10/2013'),
(28732269,'11/5/2013','11/6/2013'),
(12711280,'11/4/2013','11/12/2013'),
(11292137,'11/4/2013','11/12/2013'),
(66248244,'11/4/2013','11/12/2013')

;With Cte_Sent_Date as 
(
Select distinct Q.topic_id,Author_id
from QuestionResponse Q
Left join @Sample_Alankar S on Q.Author_ID = S.Author_id

where 
1 = 1 
and  First_Start_date between DATEADD(WEEK,@NumofWeeks*(-1),Sent_date) and Sent_date
Select distinct Q.topic_id,S.Author_id
from QuestionResponse Q
Left join @Sample_Alankar S on Q.Author_ID = S.Author_id