Changing columns collation using batch sql in sql server 2005 -


i took on databases. appears @ point default database collation changed. result columns have old default collation, new columns, added after collation changed have new collation. there's great deal of stored procedure code uses unions. when code executes happens get

cannot resolve collation conflict column 5 in select statement.

error (for instance first select returns column in collation a, whereas second select returns column in collation b). there way write sql instance select columns collation sql_latin1_general_cp1_ci_as (old collation) new collation latin1_general_ci_as ?

thanks

something should trick

  • look columns incorrect collation
  • compose alter table statement & alter column statement per incorrect column

    declare @sql nvarchar(4000)        , @tablename sysname       , @name sysname       , @datatype sysname       , @length int       , @precision int       , @scale int       , @is_nullable bit  declare cur_collations cursor local read_only select tablename = object_name(object_id)          , name          , type_name(user_type_id)          , max_length       sys.columns       collation_name = 'sql_latin1_general_cp1_ci_as'  open cur_collations  fetch next cur_collations @tablename, @name, @datatype, @length  while (@@fetch_status <> -1)   begin     if (@@fetch_status <> -2)       begin           set @sql = n'             alter table ' + quotename(@tablename) + n'             alter column ' + quotename(@name) + n' ' + quotename(@datatype) + n'(' + cast(@length nvarchar(10)) + n')              collate latin1_general_ci_as             ' + case when @is_nullable = 1 n'null' else n'not null' end + n' '           exec (@sql)       end     fetch next cur_collations @tablename, @name, @datatype, @length   end  close cur_collations deallocate cur_collations 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -