T-SQL Exec语句语法错误

时间:2012-05-14 07:05:08

标签: tsql sql-server-2005

为什么第一个语句是语法错误?

-- 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 个答案:

答案 0 :(得分:4)

这是EXECUTE的语法。您只能传递值或变量,而不能传递函数或表达式。请参阅BOL上的EXECUTE