I want to query MySql database in MSSQL using linked server however I keep getting this error: Msg 102, Level 15, State 1, Procedure uspGetTimeLog, Line 16 Incorrect syntax near '+'.
Here is the sql code below
SELECT * FROM OPENQUERY([MYSQLCONN],
'SELECT e_id, TDate, Entry, `Exit` FROM timemgt.daymaster
WHERE TDate >= ''''' + @frmDate + ''''' ')
This is working
SELECT * FROM OPENQUERY([MYSQLCONN],
'SELECT e_id, TDate, TIME_FORMAT(Entry, ''%T'') AS ''Entry'',
TIME_FORMAT(`Exit`, ''%T'') AS ''Exit'' FROM timemgt.daymaster
WHERE TDate >= ''2017-01-01'' AND TDate <= ''2017-01-01''')
This is not working
DECLARE @frmDate VARCHAR(10)
DECLARE @toDate VARCHAR(10)
SET @frmDate = '2017-01-01'
SET @toDate = '2017-01-01'
SELECT * FROM OPENQUERY([MYSQLCONN],
'SELECT e_id, TDate, TIME_FORMAT(Entry, ''%T'') AS ''Entry'',
TIME_FORMAT(`Exit`, ''%T'') AS ''Exit'' FROM timemgt.daymaster
WHERE TDate >=''' + @frmDate + ''' AND TDate <= '''+ @toDate +'''')
Error am getting
Msg 102, Level 15, State 1, Line 9 Incorrect syntax near '+'.
There after I will pass it to a temporary table