if object_id('spgeninsertsql','p') is not null
drop proc spgeninsertsql
go
create proc spgeninsertsql (@tablename varchar(256))
as
begin
declare @sql varchar(8000)
declare @sqlvalues varchar(8000)
set @sql =' ('
set @sqlvalues = 'values (''+'
select @sqlvalues = @sqlvalues + cols + ' + '',
casque beats,'' + ' ,
casque dr dre,@sql = @sql + '[' + name + '],
louboutin pas cher,'
from
(select case
when xtype in (48,52,56,
jordan shoes,59,60,62,104,
burberry,106,108,122,
burberry soldes,127) --如果是数值型或moeny型
then 'case when '+ name +' is null then ''null'' else ' + 'cast('+ name + ' as varchar)'+' end'
when xtype in (58,61) --如果是datetime或smalldatetime类型
then 'case when '+ name +' is null then ''null'' else '+''''''''' + ' + 'convert(varchar,'+ name +',120)'+ '+'''''''''+' end'
when xtype in (167) --如果是varchar类型
then 'case when '+ name +' is null then ''null'' else '+''''''''' + ' + 'replace('+ name+','''''''','''''''''''')' + '+'''''''''+' end'
when xtype in (231) --如果是nvarchar类型
then 'case when '+ name +' is null then ''null'' else '+'''n'''''' + ' + 'replace('+ name+',
louboutin,'''''''','''''''''''')' + '+'''''''''+' end'
when xtype in (175) --如果是char类型
then 'case when '+ name +' is null then ''null'' else '+''''''''' + ' + 'cast(replace('+ name+',
burberry soldes,'''''''',
abercrombie and fitch,'''''''''''') as char(' + cast(length as varchar) + '))+'''''''''+' end'
when xtype in (239) --如果是nchar类型
then 'case when '+ name +' is null then ''null'' else '+'''n'''''' + ' + 'cast(replace('+ name+','''''''','''''''''''') as char(' + cast(length as varchar) + '))+'''''''''+' end'
else '''null'''
end as cols,
burberry,name
from syscolumns
where id = object_id(@tablename)
) t
set @sql ='select ''insert into ['+ @tablename + ']' + left(@sql,len(@sql)-1)+') ' + left(@sqlvalues,len(@sqlvalues)-4) + ')'' from '+@tablename
--print @sql
exec (@sql)
end
go
在执行存储过程时需要输入表明作为参数。
例如:exec spgeninsertsql tablename
相关的主题文章:
http://embeddednet.net/sfm/index.php?topic=41962.msg174756#msg174756
http://www.cee512.org/review.asp?newsid=2284
the apb team remains first of all players. forward amado and neto. gamba osaka ensemble discharge storm 343 formation, the striker lucas, jo jae-zhen and juninho arrows shot.