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.

Sign up to request clarification or add additional context in comments.

1 Comment

You are right. The similarity to function calls in $(insert-any-programming-language) misled me. I wonder about the underlying design decision...

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.