我想從30天前在sql 中獲取兩個表的行,但我的日期列是nvarchar,我不能將它轉換爲日期 我嘗試了幾件事但不收到任何結果,並且並始終得到了一個錯誤從30天前在SQL表中返回行
這是我的查詢和 我通過@date發送TodayTime參數從程序爲sql
[dbo].[Report30Days]
@Date nvarchar(10)
as
select
coalesce(S.Date,B.Date) Date,
coalesce(S.TAccount,0) sTAccount,
coalesce(S.Remaining,0) sRemaining,
coalesce(B.TAccount,0) bTAccount,
coalesce(B.Remaining,0) bRemaining
from
(select
Date,sum(TAccount) TAccount, sum(Remaining) Remaining
from SaleInvoices
where
DateDiff(day,convert(datetime,@Date,110),convert(datetime,Date,110))<=30
group by Date) S
Full Outer Join
(select
Date,sum(TAccount) TAccount, sum(Remaining) Remaining
from BuyInvoices
where
DateDiff(day,convert(datetime,@Date,110),convert(datetime,Date,110))<=30
group by Date) B
on
S.Date=B.Date
我的問題是在這裏
where
DateDiff(day,convert(datetime,@Date,110),convert(datetime,Date,110))<=30
日期列於表和@date格式=> 2017年2月2日
之後執行該過程時,將顯示該錯誤:
一個nvarchar數據類型到datetime數據類型轉換導致超出範圍的價值。
請指導我
非常感謝您
你正在得到什麼確切的錯誤?另外,「Date」的數據類型是什麼? –
爲什麼你需要將今天的日期作爲參數傳遞給存儲過程?您可以在SQL腳本中獲取今天的日期。另外,爲什麼你必須將參數類型定義爲nvarchar? – Sparrow
您可以使用較不明確的日期示例嗎?像12月31日? – SqlZim