2

I have an OPENQUERY statement

SELECT * 
FROM OPENQUERY (NETLINE, 
                'SELECT * FROM XCREW.CTNAISV_HOTELCREW where RESERVATION_DATE = ''2015-05-01''')

After executing it I have error message on 2015

How to pass datetime as parameter in OPENQUERY ?

Thanks

jarlh
  • 42,561
  • 8
  • 45
  • 63
Zvonimir Tokic
  • 443
  • 9
  • 19

2 Answers2

0

Try this instead. Explicitly convert it to a datetime (maybe convert it to the proper datetime format you use).

SELECT * 
FROM OPENQUERY (NETLINE, 
                'SELECT * FROM XCREW.CTNAISV_HOTELCREW where RESERVATION_DATE = CONVERT(datetime,''2015-05-01'')')

The proper format can also applied using CONVERT(datetime, N'2015-05-01', 112) (for example).

Ionic
  • 3,884
  • 1
  • 12
  • 33
0

quotes were wrong. This query execute correctly

SELECT *
FROM OPENQUERY (NETLINE,
  'SELECT *
  FROM XCREW.CTNAISV_HOTELCREW
  WHERE RESERVATION_DATE BETWEEN ''01-01-2015'' AND ''05-05-2015'''
)

and also date format was wrong

Dale K
  • 25,246
  • 15
  • 42
  • 71
Zvonimir Tokic
  • 443
  • 9
  • 19