首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎的把三条SQL语句连接起来

2012-09-29 
怎样把三条SQL语句连接起来,怎样把三条SQL语句连接起来,或是后两条用 或 语句写为一条也可以sSQL1 selec

怎样把三条SQL语句连接起来,
怎样把三条SQL语句连接起来,或是后两条用 或 语句写为一条也可以
sSQL1= "select hacref.session.* ,hacref.session_2.* from hacconf.resource,hacconf.auditor_session_author,hacref.session left join hacref.session_2 on(id = session_id) where " "starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr;sSQL+= " and endtime > 1";
sSQL1+=" and hacref.session.appname=hacconf.resource.name and hacconf.resource.dev_id=hacconf.auditor_session_author.dev_id ";
str.Format("and hacconf.auditor_session_author.manager_id=%d",theApp.m_nCurUserID);
sSQL1+=str;
   
sSQL2="select distinct * from hacref.session left join hacref.session_2 on(id = session_id) where "starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr and endtime = 1";  
  
sSQL3=" select distinct * from hacref.session left join hacref.session_2 on(id = session_id) where " "starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr and endtime = 3 and serverIP="[UNKNOWN]"";

[解决办法]
"starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr and endtime = 1 or (starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr and endtime = 3 and serverIP="[UNKNOWN]")";
[解决办法]
Union All
[解决办法]
或者
select * from tb where id=1
union
select * from tb where id=2;

注意第一句后面不能有分号

热点排行