I hope someone can shed some light on this. I can't believe I never noticed this issue before. It's really irritating me.
Why is it not possible to do inline concatenation using stored procs (I haven't tried with function开发者_如何学运维s yet)?
Look at this example I created. This will not complete with execution. It will fail on line 5.
It seems like overkill to make the developer have to create a variable possibly and issue a set
command anywhere that it is required to insert some concatenated value into a sp.
Please tell me I'm over looking something.
DECLARE @WORLD NVARCHAR(MAX)
SET @WORLD = 'WORLD'
PRINT 'HELLO ' + @WORLD
exec sp_profileColumn 'dbo' + '.' + @WORLD --THIS STATEMENT FAILS
set @WORLD = 'dbo' + '.' + @WORLD
exec sp_profileColumn @WORLD --LOGICALLY THIS STATEMENT IS THE SAME AS LINE 5, CORRECT?
I agree that it is unfortunate, but it has been that way for a long time in SQL Server.
精彩评论