Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Too much validation from SQL Server
Message
From
26/02/2010 03:54:49
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01451147
Message ID:
01451158
Views:
34
Well, with this new script, it takes care of everything:
DECLARE @dropIndexSql nvarchar(4000)
SET @dropIndexSql = N'DROP INDEX [Advertis].[AddUser]'
BEGIN TRY
   PRINT @dropIndexSql
   EXEC sp_executesql @dropIndexSql
END TRY
BEGIN CATCH
   Print ERROR_MESSAGE()
END CATCH
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Advertis' AND COLUMN_NAME = 'AddUser')
   BEGIN
      BEGIN TRY
         PRINT @dropIndexSql
         SET @dropIndexSql = N'ALTER TABLE [Advertis] ADD [AddUser] int'
         EXEC sp_executesql @dropIndexSql
      END TRY
      BEGIN CATCH
         Print ERROR_MESSAGE()
      END CATCH
   END
   ELSE
   BEGIN
      BEGIN TRY
         SET @dropIndexSql = N'ALTER TABLE [Advertis] ADD [AddUser-Temporary] int'
         PRINT @dropIndexSql
         EXEC sp_executesql @dropIndexSql
         SET @dropIndexSql = N'UPDATE [Advertis] SET [AddUser-Temporary]=AddUser'
         PRINT @dropIndexSql
         EXEC sp_executesql @dropIndexSql
         SET @dropIndexSql = N'ALTER TABLE [Advertis] DROP COLUMN [AddUser]'
         PRINT @dropIndexSql
         EXEC sp_executesql @dropIndexSql
         PRINT 'Renaming the field'
         EXEC sp_RENAME 'Advertis.AddUser-Temporary', 'AddUser' , 'COLUMN'
      END TRY
      BEGIN CATCH
         Print ERROR_MESSAGE()
      END CATCH
   END
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform