This is the first time that I have created a stored procedure and I have no clue what I am doing wrong.
I am getting the following error:
Msg 7202, Level 11, State 2, Procedure update_call_details, Line 8
Could not find server 'SELECT TOP 1 b' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
Stored procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[update_call_details]
AS
BEGIN
DECLARE @EventTime varchar(50)
SET @EventTime = 'SELECT TOP 1 b.event_time FROM db1.dbo.TableName as b order by b.event_time desc'
EXEC @EventTime
INSERT INTO Sdb1.dbo.TableName
SELECT
CAST(START_TIME as DATE) as START_TIME,
AGENT_ID,
GRP_DBID,
DIRECTION,
ANI, DNIS, TRACKNUM,
N_HOLD, T_HOLD,
N_CONFRENCE, T_CONFRENCE,
N_TRANSFER, T_TRANSFER,
T_WRAP_UP,
TALK_TIME,
CAST(END_TIME as DATE) as END_TIME,
CAST(EVENT_TIME as DATE) as EVENT_TIME
FROM
OPENQUERY(db2, 'SELECT * FROM db2.TableName
WHERE EVENT_TIME > "@EventTime"')
END