1

I'm new in SQL . I'm converting mysql to SQL.

I've found an error when I use DateAdd function.

Here is the query:

SELECT
      [id],
      [test_code],
      [test_name],
      [test_price],
      [discount],
      DATEADD(CURRENT_TIMESTAMP, INTERVAL [test_duration] HOUR) as delivery_date,       
      [is_active]
    FROM [icddrb_tblab].[dbo].[tb_test]
    WHERE [icddrb_tblab].[dbo].[tb_test].[id] =0

It gives error: Msg 102, Level 15, State 1, Line 7

Incorrect syntax near 'test_duration'.'

Can anyone suggest me, where is the issue.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • If you use SQLServer you can try `DATEADD(HOUR,[test_duration],GETDATE()) as delivery_date`. – Sergey Menshov Nov 16 '17 at 05:16
  • "Microsoft SQL Server" is sometimes (frustratingly) referred to as just "SQL", but MS does NOT produce a product called "SQL". Please always refer to the MS produced database by "sql-server" in the tags. SQL is a language. – Paul Maxwell Nov 16 '17 at 05:19

2 Answers2

1

DATEADD function takes parameter like this DATEADD (datepart , number , date )

You can use this.

SELECT
      [id],
      [test_code],
      [test_name],
      [test_price],
      [discount],
      DATEADD(HOUR, [test_duration], CURRENT_TIMESTAMP ) as delivery_date,       
      [is_active]
    FROM [icddrb_tblab].[dbo].[tb_test]
    WHERE [icddrb_tblab].[dbo].[tb_test].[id] =0
Serkan Arslan
  • 13,158
  • 4
  • 29
  • 44
0

Solved:

DATEADD(HOUR,[test_duration], CURRENT_TIMESTAMP) as delivery_date,

its the actual format.

neer
  • 4,031
  • 6
  • 20
  • 34