I'm trying to create a stored procedure that will trigger every 15 minutes
via a server agent job.
I need to pull data back from a linked server to our SQL server. The tables have the same columns/fields just different names.
I know the linked server logic works because I get the data if I run this code.
[code]select * FROM OPENQUERY(MyLinkServer, ' select WCHTIK,WCHSRC,WCHIDTE,WCHITIME from extranet.WCTLH')[/code]
If I run this code below I get this error.
iSeries Access ODBC Driver][DB2 UDB]SQL0104 - Token . was not valid. Valid tokens: , FROM INTO
[code]
Declare @TimeDifference as INT
SET @TimeDifference = -15
DECLARE @NewDateTime Datetime
set @NewDateTime = DATEADD(mi,@TimeDifference, getdate())
DECLARE @CompDate varchar(10)
set @CompDate = convert(varchar(10), @NewDateTime, 20)
select @CompDate
DECLARE @CompTime varchar(8)
set @CompTime = CONVERT(VARCHAR(8), @NewDateTime, 108)
select @CompTime
declare @strSQL as NVARCHAR(4000)
set @strSQL = ''
set @strSQL = @strSQL + 'insert into WebHeaderControl '
set @strSQL = @strSQL + '(WebHeaderTicketNumber,WebHeaderSource,'
set @strSQL = @strSQL + 'WebHeaderInDate,WebHeaderinTime)'
set @strSQL = @strSQL + 'select * FROM OPENQUERY(MyLinkServer, '
set @strSQL = @strSQL + '''select WCHTIK,WCHSRC,'
set @strSQL = @strSQL + 'WCHIDTE,WCHITIME '
set @strSQL = @strSQL + 'from extranet.WCTLH '
set @strSQL = @strSQL + 'WHERE WCHIDTE = ' + @CompDate + ' and WCHITIME >= ' + @CompTime + ''')'
exec(@strSQL)[/code]
I'm not an SQL expert and this is my first attempt at using a linked server..
Any ideas?
Thanks in advance
Sorry for the code being messed up.
Did not see the CODE button in IE9
Software/Hardware used:
SQL Server 2000
ASKED:
March 22, 2013 3:57 PM
UPDATED:
March 22, 2013 4:32 PM
I added a comment, but it’s not showing up for some unknown reason. I guess we’ll wait until morning to see if it gets released. — Tom
Second try to put the comment in still gives nothing. Sorry; not much I can do. — Tom
Thanks for the tip Tom, that fixed it… Ran into a related issue but found a work around for it.