Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sp_executesql 3

Status
Not open for further replies.

mimi2

Technical User
Apr 2, 2002
407
CA
I am still at the same point.
What should i change to make this code work? Thanks

The error i get is:
Cannot use the OUTPUT option when passing a constant to a stored procedure

this is part of a stored procedure
declare sql nvarchar(200), maxdate datetime

SET @sql = N'SELECT @m = MAX(date) FROM ' + @link_server + '.database1.dbo.table1
EXEC sp_executesql @sql, N'@m datetime OUTPUT', MaxDate OUTPUT
print ('max= ' + cast (@MaxDate as varchar (40)) )
 
May need to go at it this way ... maybe - lol


CREATE PROCEDURE MyProcedure @MaxDate dateteime output

declare @sql varchar(400)

SET @sql = N'SELECT @MaxDate = MAX(date)
FROM ' + @link_server + '.database1.dbo.table1'

EXEC (@sql)

print ('max= ' + cast (@MaxDate as varchar (40)) )

Thanks

J. Kusch
 
Add the @ in front of the maxdate variable when calling the SP.

--James
 
I am the one who's on crack!!
@ was missing as JamesLean pointed out.
Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top