I want to fetch up rows of two tables from 30 days ago in sql but my date column is nvarchar and I cant convert it to date I tried several things but But did not receive any result and And always got an error
this is my query and I send TodayTime parameter from program by @Date to 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
my problem is here
where
DateDiff(day,convert(datetime,@Date,110),convert(datetime,Date,110))<=30
Date Column in Tables and @Date Format => 2017/02/02
After execute this procedure , This error will be displayed :
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
Please Guide Me
Thank you very much