SQL Server: procedure call, built-in concatenation is not possible?

I am using SQL Server 2008 R2 and wondering if there is another way to write something like

EXEC dbo.myProcedure (SELECT columnName FROM TableName)

or

EXEC dbo.myProcedure @myStringVariable + 'other text'

so that this procedure actually causes work , without first putting all the material in a variable.

+5
source share
2 answers

Not sure what you mean by "not putting all the stuff in a variable." However, I have a solution, although it may go against what I think you mean. But it doesn’t matter here.

DECLARE @SQL VARCHAR(MAX)

SET @SQL = ''

SELECT
    @SQL = @SQL + 'EXEC SprocName ''' + ColumnName + ''''
FROM
    MyTable 

EXEC (@SQL)

I use this method all the time when I need to execute sproc based on specific values ​​from a table.

0
source

SP .

, @myStringVariable .

@myStringVariable proc.

0

All Articles