Create Insert 

Posted by Philip Leitch Tuesday, November 10, 2009 2:40:42 AM
Create  proc  Create_Insert(@Table_Name as varchar(500))
as
/*
www.prlsoftware.com
Author: Philip Leitch
Date: 2009
Purpose: This procedure creates an easy "Insert" script - useful for transfering data.
Copyright: Philip Leitch 2009
Licensing: This code may be used or modified but if the code is included in a software package attribution to me must be made.
Liability: The developer assumes all liability when using this code.
*/
begin
Declare @SQL as varchar(8000)
select @sql = case when @sql is null then '' else @SQL + ', '''''' +' end + char(10) +
'isnull(' + case when syscolumns.collation is not null then
' replace([' + Name + '] , '''''''','''''''''''')  '
else
'  cast([' + Name + '] as varchar) '
end +  ', ''null'') + '''''' '
from syscolumns where id = object_id(@Table_Name)
set @sql = 'Select ''insert into [' + @Table_Name + '] Values('''''' + ' + @sql  + ')''' +
 char(10) + ' from [' + @Table_Name + ']'
print @sql
exec (@sql)

end


Copyright 2009 Philip Leitch