现在公司用的是SQL2005数据库,导数据时无法自动 生成数据脚本。没办法,只有用SQL语句来自动生成对应的Insert语句。
好在目标表只有4个字段,id,name,Parentid,FullName.而id 是自增长的,无需插入。
下面是SQL语句:
select 'Insert into cxzs_Type (name,Parentid,FullName) values ('''+name+''','+ISNULL(cast(Parentid as varchar),'NULL')+
','''+FullName+''''+')'
from cxzs_Type
最后会生成类似下面的SQL Insert语句:
Insert into cxzs_Type (name,Parentid,FullName) values ('按节日分类',NULL,'按节日分类')