title: How to Change All SQL Columns of money and smallmoney into decimal?
body: <p>I have tried to do it using the answer to <a href="https://stackoverflow.com/questions/1327548/how-to-change-all-sql-columns-of-one-datatype-into-another/">this question</a> by modifying it to the following, but I'm getting an error on: </p>
  
  <pre><code>fetch next from maxcols into @schema, @table, @col, @dtype
  </code></pre>
  
  <blockquote>
    <p>Msg 8114, Level 16, State 5, Line 25<br>
    Error converting data type nvarchar to decimal.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>declare @schema nvarchar(255)
  declare @table nvarchar(255)
  declare @col nvarchar(255)
  declare @dtype decimal(19,8)
  declare @sql nvarchar(max)
  
  declare maxcols cursor for
      select
          c.TABLE_SCHEMA, c.TABLE_NAME,
          c.COLUMN_NAME, c.DATA_TYPE
      from
          INFORMATION_SCHEMA.COLUMNS c
      inner join 
          INFORMATION_SCHEMA.TABLES t on c.TABLE_CATALOG = t.TABLE_CATALOG
                                      and c.TABLE_SCHEMA = t.TABLE_SCHEMA
                                      and c.TABLE_NAME = t.TABLE_NAME
                                      and t.TABLE_TYPE = 'BASE TABLE'
      where
          c.DATA_TYPE like '%money'
  
  open maxcols
  
  fetch next from maxcols into @schema, @table, @col, @dtype
  
  while @@FETCH_STATUS = 0
  begin
      set @sql = 'alter table [' + @schema + '].[' + @table + 
          '] alter column [' + @col + '] ' + @dtype
      exec sp_executesql @sql
  
      fetch next from maxcols into @schema, @table, @col, @dtype
  end
  
  close maxcols
  deallocate maxcols
  </code></pre>