如何使用sproc param作为列别名?例如:
SELECT '12345' AS @MySprocParam
我尝试了以下sql,但它不起作用:
DECLARE @MySprocParam VARCHAR(50) = 'TestAlias'
SELECT 'ASDF' AS @MyProcParam
答案 0 :(得分:2)
你需要动态的sql
DECLARE @MySprocParam VARCHAR(50) = 'TestAlias'
SET @MyProcParam = QUOTENAME(@MyProcParam)
exec( 'SELECT ''ASDF'' AS '+@MyProcParam)