Can someone please tell me what I am missing here? I thought my code look beautiful until I ran the last 2 lines for yesterday's results. the columns are there but they are empty. If I use the commmented out date line, the data shows up perfectly. This makes me think the error is in select convert statement... but I have tried every---thing.
有人可以告诉我这里缺少什么吗?我认为我的代码看起来很漂亮,直到我为昨天的结果运行最后两行。列在那里,但它们是空的。如果我使用已注释的日期行,则数据会完美显示。这让我觉得错误是在选择转换语句中...但我已经尝试过每一件事。
SELECT RTRIM(r.acct_no) as acct_no, CONVERT(varchar,t.doc_date,101)as doc_date, t.doc_amt,
LEFT(t.batch_no,4) as batch_no
FROM ESUTRANH t
INNER JOIN ESUTRAND d on t.tran_id = d.tran_id
INNER JOIN ESUACCTR r on d.acct_id = r.acct_id
INNER JOIN ESUCUSTJ j on r.acct_id = j.acct_id
WHERE (t.batch_no is null or LEN(t.batch_no) > 1)
--AND t.doc_date between '05/09/2017' and '05/10/2017'
AND t.doc_date >= dateadd(day,datediff(day,1,GETDATE()),0)
AND t.doc_date < dateadd(day,datediff(day,0,GETDATE()),0)
2 个解决方案
#1
0
Depending on the connection/server language settings AND t.doc_date between '05/09/2017' and '05/10/2017'
can mean:
根据连接/服务器语言设置和'05 / 09/2017'和'05/10 / 2017之间的t.doc_date'可以表示:
- doc_date between 05-September-2017 and 5-October-2017,
'DD/MM/YYYY'
format. - 2017年9月5日至2017年5月5日期间的doc_date,'DD / MM / YYYY'格式。
- doc_date between 09-May-2017 and 10-May-2017,
'MM/DD/YYYY'
format. - doc_date在2017年5月9日至2017年5月10日期间,'MM / DD / YYYY'格式。
It's better using a date format that doesn't depend on the language configuration, like 'YYYYMMDD'
, for example AND t.doc_date between '20170509' and '20170510'
.
最好使用不依赖于语言配置的日期格式,例如'YYYYMMDD',例如'20170509'和'20170510'之间的AND t.doc_date。
#2
0
From your query,
--AND t.doc_date between '05/09/2017' and '05/10/2017'
Above line is getting data for 1 month.
根据您的查询,在'05 / 09/2017'和'05 / 10/2017之间的--AND t.doc_date'以上行获取1个月的数据。
And below code is getting data for yesterday.
AND t.doc_date >= dateadd(day,datediff(day,1,GETDATE()),0)
AND t.doc_date < dateadd(day,datediff(day,0,GETDATE()),0)
Can you please check whether you table has data for yesterday.
以下代码是获取昨天的数据。 AND t.doc_date> = dateadd(day,datediff(day,1,GETDATE()),0)AND t.doc_date
#1
0
Depending on the connection/server language settings AND t.doc_date between '05/09/2017' and '05/10/2017'
can mean:
根据连接/服务器语言设置和'05 / 09/2017'和'05/10 / 2017之间的t.doc_date'可以表示:
- doc_date between 05-September-2017 and 5-October-2017,
'DD/MM/YYYY'
format. - 2017年9月5日至2017年5月5日期间的doc_date,'DD / MM / YYYY'格式。
- doc_date between 09-May-2017 and 10-May-2017,
'MM/DD/YYYY'
format. - doc_date在2017年5月9日至2017年5月10日期间,'MM / DD / YYYY'格式。
It's better using a date format that doesn't depend on the language configuration, like 'YYYYMMDD'
, for example AND t.doc_date between '20170509' and '20170510'
.
最好使用不依赖于语言配置的日期格式,例如'YYYYMMDD',例如'20170509'和'20170510'之间的AND t.doc_date。
#2
0
From your query,
--AND t.doc_date between '05/09/2017' and '05/10/2017'
Above line is getting data for 1 month.
根据您的查询,在'05 / 09/2017'和'05 / 10/2017之间的--AND t.doc_date'以上行获取1个月的数据。
And below code is getting data for yesterday.
AND t.doc_date >= dateadd(day,datediff(day,1,GETDATE()),0)
AND t.doc_date < dateadd(day,datediff(day,0,GETDATE()),0)
Can you please check whether you table has data for yesterday.
以下代码是获取昨天的数据。 AND t.doc_date> = dateadd(day,datediff(day,1,GETDATE()),0)AND t.doc_date