-3

I'm hitting error while running this statement in sql server..

DECIMAL(TO_CHAR(CURRENT TIMESTAMP -1 DAYS,'yyyymmdd')8,0)
pquest
  • 3,151
  • 3
  • 27
  • 40
Gyan05
  • 15
  • 2
  • Is this MS sql server? What specific error are you getting? – pquest Dec 26 '14 at 13:14
  • It throws error as SQL##f - SqlState: 37000, ErrorCode: 156, ErrorMsg: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'CURRENT'. I tried with CAST/CONVERT also but not getting the result – Gyan05 Dec 26 '14 at 13:28
  • I want to add previous day records. Yes it's Sql server only. This statement works fine in DB2 though. – Gyan05 Dec 26 '14 at 13:34
  • the sql languages between db2 and ms sql server are not exactly the same. Can you tell me what you expect this specific statement to do? – pquest Dec 26 '14 at 13:58
  • I want my query to go back one day to the system date and extract the data. The Date field should be in YYYYMMDD format only – Gyan05 Dec 26 '14 at 14:27

1 Answers1

0

For MSSQL it's CURRENT_TIMESTAMP, you forgot the underscore. I'm not sure what you're trying to accomplish with TO_CHAR... But that's not the only problem with this syntax. You're mixing together a lot of different RDBMS's here...

I'm just guessing what you're trying to do but this seems to be what you're looking for:

 SELECT CAST(DATEADD(DD, -1, CURRENT_TIMESTAMP) AS DECIMAL(8, 0))
Michael McGriff
  • 793
  • 10
  • 20
  • Thanks Michael. That works. I was trying my query to go back one day and extract the data. Right now I see no data for the previous day though in DB. Thanks again – Gyan05 Dec 26 '14 at 15:17