Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Too much validation from SQL Server
Message
 
To
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:
01451171
Views:
32
Sorry,
but I can't answer earlier than now.
I'm glad you figured out :-)


>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
>
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform