Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

How should I pass a table name into a stored proc?

SELECT @ActualTableName = QUOTENAME( TABLE_NAME )
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = @PassedTableName

DECLARE @sql AS NVARCHAR(MAX)
--SELECT @sql = 'SELECT COUNT(*) FROM [' + @ActualTableName + '];'

-- changed to this
SELECT @sql = 'SELECT COUNT(*) FROM ' + @ActualTableName + ';'

EXEC(@SQL)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #I #pass #table #stored
ADD COMMENT
Topic
Name
6+8 =