Groups | Blog | Home
all groups > sql server misc > july 2004 >

sql server misc : EXEC Command with 'EXEC' as parameter fires twice



mark
7/22/2004 10:34:52 PM
I created the procedure below in a SQLServer 2000 environment to export a
SQL query to a log file. The procedure exports all of the records correctly
but the procedure is executing 'someproc' twice.

Any help will be much appreciated.

Thanks,
Mark




CREATE PROCEDURE sp_queryToFile
@query VARCHAR(2000),
@file VARCHAR(250)
AS
DECLARE
BEGIN
@bcpCommand VARCHAR(4000),
@errorFile VARCHAR(250)
SET @errorFile = 'C:\sp_queryToFileErrors.txt'
SET @bcpCommand = 'bcp "' + @query + '" queryout "' + @file + '" -T -c -e
"' + @errorFile + '"'
EXEC master..xp_cmdshell @bcpCommand
END
GO




EXEC master..sp_queryToFile 'EXEC somedb..sp_someproc', 'C:\export.txt'

mmmc_reptail NO[at]SPAM hotmail.com
7/23/2004 2:00:07 AM
Well, I tried that with a one change and it worked.
I moved the DECLARE statement after BEGIN and it worked.
somproc only excecuted once.

Hope it works for you too.

----
mkarja


[quoted text, click to view]
AddThis Social Bookmark Button