Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Referencing a field from a SQL
Message
De
04/03/2008 22:53:47
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01298743
Message ID:
01298775
Vues:
25
>
>DECLARE @CONSTRAINT_NAME nvarchar(128)
>
>SELECT @CONSTRAINT_NAME = CONSTRAINT_NAME
>  FROM INFORMATION_SCHEMA.KEY_USAGE
>  WHERE ...
>
>DECLARE @sql varchar(4000)
>SET @sql = 'ALTER TABLE DROP CONSTRAINT ' + @CONSTRAINT_NAME
>EXECUTE (@sql)
>
Inside a IF EXISTS condition, the syntax is not supported as is:
DECLARE @Constraint_Name nvarchar(128)
DECLARE @SQL varchar(4000)

IF EXISTS(SELECT @Constraint_Name = Constraint_Name
 FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
 WHERE Table_Name = 'ArchiveRetrieval')
if @@rowcount = 1
   BEGIN
      SET @SQL = 'ALTER TABLE ArchiveRetrieval DROP CONSTRAINT ' + @Constraint_Name
      EXECUTE(@SQL)
   END
It says:

"Incorrect syntax near '='."
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform