根据基本表结构及其数据生成INSERT...的SQL

2008-04-02 10:48:14来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

create proc spGenInsertSQL
@TableName as varchar(100)
as
--declare @TableName varchar(100)
--set @TableName = 'orders'
--set @TableName = 'eeducation'
DECLARE xCursor CURSOR FOR
SELECT name,xusertype
FROM syscolumns
WHERE (id = OBJECT_ID(@TableName))
declare @F1 varchar(100)
declare @F2 integer
declare @SQL varchar(8000)
set @sql ='SELECT 'INSERT INTO ' @TableName ' VALUES(''
OPEN xCursor
FETCH xCursor into @F1,@F2
WHILE @@FETCH_STATUS = 0
BEGIN
set @sql =@sql
case when @F2 IN (35,58,99,167,175,231,239,61) then ' case when ' @F1 ' IS NULL then '' else '''' end ' else ' ' end
'replace(ISNULL(cast(' @F1 ' as varchar),'NULL'),'''','''''')'
case when @F2 IN (35,58,99,167,175,231,239,61) then ' case when ' @F1 ' IS NULL then '' else '''' end ' else ' ' end
char(13) '',''
FETCH NEXT FROM xCursor into @F1,@F2
END
CLOSE xCursor
DEALLOCATE xCursor
set @sql = left(@sql,len(@sql) - 5) ' ')' FROM ' @TableName
print @sql
exec (@sql)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: Decryptencryptedstoredprocedures

下一篇: SQLServer的安全隐患:不要以为黑掉的只是SQLSERVER而已。