1

Why is the first statement a syntax error?

-- this does not work: "incorrect syntax near the keyword 'system_user'"
exec dbo.spEmployee_GetRecords @pLoginName = system_user

-- this works
declare @p nvarchar(30);
select @p=system_user
exec dbo.spEmployee_GetRecords @pLoginName = @p

(SQL Server 2005 Express Edition)

1 Answer 1

4

This is the syntax of EXECUTE. You can only pass values or variables, not functions or expressions. See EXECUTE on BOL.

1
  • You are right. The similarity to function calls in $(insert-any-programming-language) misled me. I wonder about the underlying design decision... May 14, 2012 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.