RE: An insert exec statement cannot be nested. Pls HELP.
From: BlueDolphin (BlueDolphin_at_discussions.microsoft.com)
Date: 11/04/04
- Next message: Iain Duthie: "Re: Converting varchar value to a column of data type int."
- Previous message: Mal .mullerjannie_at_hotmail.com>: "MCDBA"
- In reply to: David Portas: "RE: An insert exec statement cannot be nested. Pls HELP."
- Next in thread: BlueDolphin: "RE: An insert exec statement cannot be nested. Pls HELP."
- Reply: BlueDolphin: "RE: An insert exec statement cannot be nested. Pls HELP."
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 4 Nov 2004 01:44:01 -0800
Hello David,
Please ignore my previous message, I managed to settle the
sp_addlinkedserver issue in the stored proc.
However, another problem arise which I can't figure out what is wrong.
The error encountered is as indicated below:
Server: Msg 911, Level 16, State 1, Line 41
Could not locate entry in sysdatabases for database 'SELECT * FROM
OPENQUERY(LOCALSERVER,'SET NOCOUNT ON SET FMTONLY OFF EXEC DATA'. No entry
found with that name. Make sure that the name is entered correctly.
I'm trying to use OPENQUERY with a dynamic sql string so that i can pass in
a variable to the stored proc that I'm calling.
My stored proc is as shown below:
CREATE PROCEDURE GetList
@PID varchar(20)
AS
DECLARE @CmdString varchar(1000)
DECLARE @remotesql nvarchar(4000)
SET @remotesql = 'SET NOCOUNT ON SET FMTONLY OFF EXEC
DATA.dbo.EMRX_Retrieve_Test 4, ' + dbo.quotestring(@PID) + ', NULL'
SET @CmdString = 'SELECT * FROM OPENQUERY(LOCALSERVER,' +
dbo.quotestring(@remotesql) + ')'
IF (Select count(*) From OptOutPatient where patientid = @PID) = 0
BEGIN
CREATE TABLE #Temp_List
(
ID numeric,
StartDtm varchar(32),
FacilityCode varchar(10)
)
SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
IF EXISTS (SELECT * FROM master..sysservers WHERE srvname = 'LOCALSERVER')
EXEC sp_dropserver LOCALSERVER, 'droplogins'
EXEC sp_addlinkedserver @server='LOCALSERVER', @srvproduct='',
@provider='SQLOLEDB', @datasrc=@@servername
INSERT INTO #Temp_List (ID, StartDtm, FacilityCode)
EXEC @CmdString
SELECT CONVERT(datetime, CONVERT(char(10), StartDtm, 101), 101) AS
StartDtm, FacilityCode
FROM #Temp_List
GROUP BY CONVERT(datetime, CONVERT(char(10), StartDtm, 101), 101),
FacilityCode
ORDER BY CONVERT(datetime, CONVERT(char(10), StartDtm, 101), 101) DESC
DROP TABLE #Temp_List
EXEC sp_dropserver LOCALSERVER, 'droplogins'
END
ELSE
BEGIN
RETURN 1
END
GO
The CmdString value when selected out looks like this :
SELECT * FROM OPENQUERY(LOCALSERVER,'SET NOCOUNT ON SET FMTONLY OFF EXEC
DATA.dbo.EMRX_Retrieve_Test 4, ''S4567891A'', NULL')
Could you kindly please advise me what could be the mistake and how to
resolve it?
Much Thanks.
=====================================================
"David Portas" wrote:
> http://www.sommarskog.se/share_data.html
>
> --
> David Portas
> SQL Server MVP
> --
>
- Next message: Iain Duthie: "Re: Converting varchar value to a column of data type int."
- Previous message: Mal .mullerjannie_at_hotmail.com>: "MCDBA"
- In reply to: David Portas: "RE: An insert exec statement cannot be nested. Pls HELP."
- Next in thread: BlueDolphin: "RE: An insert exec statement cannot be nested. Pls HELP."
- Reply: BlueDolphin: "RE: An insert exec statement cannot be nested. Pls HELP."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|