Chad
Chad

Reputation: 24689

Passing a varchar result of a function as a varchar parameter is giving an error

The first parameter of my stored procedure, usp_LogMessage_Begin, accepts a varchar field as the name of the calling routine. I would like to use the Object_NAME function to return this name as so:

EXEC @LogMessageId = usp_LogMessage_Begin OBJECT_NAME(@@PROCID), 'Begin deleting all records in CBH_REBATBL...'    

But I get this error:

Msg 102, Level 15, State 1, Procedure usp_BFAncl01_Reset, Line 22
Incorrect syntax near 'OBJECT_NAME'.

This will work:

declare @SPName varchar(512)  = OBJECT_NAME(@@PROCID)
    EXEC @LogMessageId = usp_LogMessage_Begin @SPName, 'Begin deleting all records in CBH_REBATBL...'    

but I would rather not create a temporary variable. Does T-SQL not support this type of in-place function evaluation?

Upvotes: 1

Views: 432

Answers (1)

Martin Smith
Martin Smith

Reputation: 453287

No it doesn't support this.

There is a connect item request to upvote for this here: T-SQL: use scalar functions as stored procedure parameters

Upvotes: 1

Related Questions