Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic SQL
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Titre:
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01466109
Message ID:
01466114
Vues:
69
Try
SET @DynamicSQL = 'SELECT COUNT(*) AS ''Countof ' + (@TableNameVar) + ''' FROM ' + @TableNameVar
>I am attempting to display a count of the rows in a table called ContactUpdates in the AP Database. However, I am using a variable named @TableNameVar to contain the name of the table which I obtain by using a SQL statement sort of like a derived table, as in this: SET @TableNameVar = 'SELECT MIN(name) from sys.tables' , but it isn't quite working yet. This is for an exercise in my T-SQL class.
>
>
>USE AP
>
>DECLARE @DynamicSQL VARCHAR(300)
>DECLARE @TableNameVar VARCHAR(20)
>SET @TableNameVar = 'SELECT MIN(name) from sys.tables'
>
>SET @DynamicSQL = 
>	'SELECT COUNT(*) AS Countof' + (@TableNameVar) + ' FROM ' + @TableNameVar
>
>EXEC (@DynamicSQL)
>
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform