Reputation: 15
I want to fetch previous day
record from the table using a date field in Sql Server
.
However I'm using the below sql statements but it's not giving any record.
TDTE = CAST(DATEADD(DD,-1,CURRNT_TIMESTAMP) AS DECIMAL(8,0))
OR
TDTE=CAST(DATEADD(DD,-1,GETDATE())AS DECIMAL(8,0))
where TDTE
column is in YYYYMMDD
format.
Upvotes: 1
Views: 276
Reputation: 21281
Try this.
Where TDTE = CONVERT(VARCHAR(10), DATEADD(DAY,-1,GETDATE()), 112)
OR(in decimal format)
Where TDTE = CAST(CONVERT(VARCHAR(10), DATEADD(DAY,-1,GETDATE()), 112)AS DECIMAL(18,0))
Upvotes: 1
Reputation: 93694
Remove the Cast
function Dateadd
returns Date
not a Integer
value. Try this.
Where TDTE = Cast(DATEADD(DD,-1,GETDATE()) as Date)
Upvotes: 2