Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=green]-- Create a table variable to store the ALTER commands
[/color]
[COLOR=blue]Declare[/color] @Temp [COLOR=blue]Table[/color](Id [COLOR=blue]Integer[/color] [COLOR=blue]Identity[/color](1,1), ConvertToVarChar [COLOR=blue]varchar[/color](1000), ConvertToUDT [COLOR=blue]varchar[/color](1000))
[COLOR=green]-- Get the ALTER commands
[/color][COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp(ConvertToVarChar, ConvertToUDT)
[COLOR=blue]Select[/color] [COLOR=red]'Alter Table ['[/color] + Table_Name + [COLOR=red]'] Alter Column ['[/color] + Column_Name + [COLOR=red]'] varchar(10)'[/color],
[COLOR=red]'Alter Table ['[/color] + Table_Name + [COLOR=red]'] Alter Column ['[/color] + Column_Name + [COLOR=red]'] telephone'[/color]
[COLOR=blue]From[/color] Information_Schema.Columns
[COLOR=blue]Where[/color] Domain_Name = [COLOR=red]'telephone'[/color]
[COLOR=green]-- Loop through the table variable and execute the ConvertToVarChar command
[/color][COLOR=blue]Declare[/color] @i [COLOR=blue]Int[/color]
[COLOR=blue]Declare[/color] @Max [COLOR=blue]Int[/color]
[COLOR=blue]Declare[/color] @Command [COLOR=blue]VarChar[/color](1000)
[COLOR=blue]Select[/color] @i = 1, @Max = [COLOR=#FF00FF]Max[/color](Id) [COLOR=blue]From[/color] @Temp
[COLOR=blue]While[/color] @i <= @Max
[COLOR=blue]Begin[/color]
[COLOR=blue]Select[/color] @Command = ConvertToVarChar
[COLOR=blue]From[/color] @Temp
[COLOR=blue]Where[/color] Id = @i
[COLOR=blue]Exec[/color] (@Command)
[COLOR=blue]Set[/color] @i = @i + 1
[COLOR=blue]End[/color]
[COLOR=green]-- Drop the UDT
[/color][COLOR=blue]exec[/color] sp_droptype [COLOR=red]'telephone'[/color]
[COLOR=green]-- Create the UDT with new string length
[/color][COLOR=blue]exec[/color] sp_addtype [COLOR=red]'telephone'[/color], [COLOR=red]'varchar(20)'[/color], [COLOR=red]'Not Null'[/color]
[COLOR=green]-- Loop through the table again to re-set the data type to UDT
[/color][COLOR=blue]Select[/color] @i = 1, @Max = [COLOR=#FF00FF]Max[/color](Id) [COLOR=blue]From[/color] @Temp
[COLOR=blue]While[/color] @i <= @Max
[COLOR=blue]Begin[/color]
[COLOR=blue]Select[/color] @Command = ConvertToUDT
[COLOR=blue]From[/color] @Temp
[COLOR=blue]Where[/color] Id = @i
[COLOR=blue]Exec[/color] (@Command)
[COLOR=blue]Set[/color] @i = @i + 1
[COLOR=blue]End[/color]