Torben Klein
Torben Klein

Reputation: 3116

T-SQL Exec statement syntax error

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)

Upvotes: 1

Views: 1044

Answers (1)

dan radu
dan radu

Reputation: 2782

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

Upvotes: 4

Related Questions