I have a stored procedure which accepts two parameters of type UniqueIdentifier
When I call this sproc with an explicit call to NewId() in place of one of the arguments:
exec dbo.TestArgs newid, '34131101-04DE-4B97-8FAC-49C924F7BFCE'
it fails with:
Error converting data type nvarchar to uniqueidentifier.
But passing a variable populated by NewId() into the call is fine:
DECLARE @painInTheArse UniqueIdentifier
SET @painInTheArse = NewID()
EXEC dbo.TestArgsnewid@painInTheArse,'34131101-04DE-4B97-8FAC-49C924F7BFCE'
works perfectly
To me this just seems very wrong. Can someone please explain?
Parameters passed into stored procs have to be constants. See this question.
Your solution of putting the result of the function call into a parameter first is absolutely correct…