declare @i int set @i=1 while @i<2 begin select 1 select 2 select 3 end
select top 1 * from syscolumns go select top 2 * from syscolumns go select top 3 * from syscolumns go每个语句中间加一个 go
什么都不写不行啊关键字INSERT不是期望的。有效标记是FOR WITH FETCH ORDER UNION EXCEPT OPTIMIZE
加一个 go也不行啊 关键字GO不是期望的。有效标记是FOR WITH FETCH ORDER UNION EXCEPT OPTIMIZE
try { String sql = " insert into social.grant4(personid,yearfr,monthfr,yearto,monthto,fee,operator,opertime)"; sql += " select s.personid,@yearfr,@monthfr,@yearto,@monthto,@fee,@operator,GetDate()"; sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t"; sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql += " insert into social.grant3(commid,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)"; sql += " select c.commid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()"; sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t"; sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'"; sql += " group by c.commid";
sql += " insert into social.grant2(streetid,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)"; sql += " select t.streetid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()"; sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t"; sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'"; sql += " group by t.streetid";
sql += " insert into social.grant1(branch,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)"; sql += " select t.branchid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()"; sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t"; sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'"; sql += " group by t.branchid";
------------------或者这样写----------------try { String sql = " insert into social.grant4(personid,yearfr,monthfr,yearto,monthto,fee,operator,opertime)"; sql += " select s.personid,@yearfr,@monthfr,@yearto,@monthto,@fee,@operator,GetDate()"; sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t"; sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql1 += " insert into social.grant3(commid,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)"; sql1 += " select c.commid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()"; sql1 += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t"; sql1 += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'"; sql1 += " group by c.commid";
sql2 += " insert into social.grant2(streetid,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)"; sql2 += " select t.streetid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()"; sql2 += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t"; sql2 += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'"; sql2 += " group by t.streetid";
sql3 += " insert into social.grant1(branch,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)"; sql3 += " select t.branchid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()"; sql3 += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t"; sql3 += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'"; sql3 += " group by t.branchid";
set @i=1
while @i<2
begin
select 1
select 2
select 3
end
go
select top 2 * from syscolumns
go
select top 3 * from syscolumns
go每个语句中间加一个 go
关键字GO不是期望的。有效标记是FOR WITH FETCH ORDER UNION EXCEPT OPTIMIZE
String sql = " insert into social.grant4(personid,yearfr,monthfr,yearto,monthto,fee,operator,opertime)";
sql += " select s.personid,@yearfr,@monthfr,@yearto,@monthto,@fee,@operator,GetDate()";
sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t";
sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql += " insert into social.grant3(commid,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)";
sql += " select c.commid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()";
sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t";
sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql += " group by c.commid";
sql += " insert into social.grant2(streetid,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)";
sql += " select t.streetid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()";
sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t";
sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql += " group by t.streetid";
sql += " insert into social.grant1(branch,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)";
sql += " select t.branchid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()";
sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t";
sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql += " group by t.branchid";
conn = DbManager.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();
String sql = " insert into social.grant4(personid,yearfr,monthfr,yearto,monthto,fee,operator,opertime)";
sql += " select s.personid,@yearfr,@monthfr,@yearto,@monthto,@fee,@operator,GetDate()";
sql += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t";
sql += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql1 += " insert into social.grant3(commid,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)";
sql1 += " select c.commid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()";
sql1 += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t";
sql1 += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql1 += " group by c.commid";
sql2 += " insert into social.grant2(streetid,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)";
sql2 += " select t.streetid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()";
sql2 += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t";
sql2 += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql2 += " group by t.streetid";
sql3 += " insert into social.grant1(branch,yearfr,monthfr,yearto,monthto,person,fee,total,operator,opertime)";
sql3 += " select t.branchid,@yearfr,@monthfr,@yearto,@monthto,count(personid),@fee,count(personid)*@fee,@operator,GetDate()";
sql3 += " from social.soclogin s,social.paysoc p,sqdta.community c,sqdta.street t";
sql3 += " where s.personid=p.personid and p.ispay='1' and s.livcomm = c.commid and c.streetid = t.streetid and t.branchid='"+strBranchID+"'";
sql3 += " group by t.branchid";
conn = DbManager.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();
pstmt1 = conn.prepareStatement(sql1);
pstmt1.executeUpdate();
pstmt2 = conn.prepareStatement(sql2);
pstmt2.executeUpdate();
pstmt3 = conn.prepareStatement(sql3);
pstmt3.executeUpdate();