每行SQL語句加go換行

 create table #test01(c1 int identity(1,1) ,c2 nvarchar(2000))

--篩選數據後放入表01

insert into #test01

select  'sp_addlogin ' + '''' + rtrim(ltrim(usrname)) + ''', ' + '''' + rtrim(ltrim(usrname))  + ''''     from maxusergroups

--查詢表01的行數再添加字段go

select c1,c2='go'   into #test02   from #test01

--創建新表03

create table #test03(c1 int ,c2 nvarchar(2000))

--將表01和表02的數據插入到表03

insert into #test03   select * from #test01

insert into #test03   select * from #test02

select * from #test01 order by c1,c2

select * from #test02 order by c1,c2

select * from #test03 order by c1,c2  --最終結果

原文地址:https://www.cnblogs.com/Snowfun/p/1836400.html