主题:求助(SQL语句在ASP中的执行问题)
数据库:SQL 两个表:TEST1,TEST2 (字段一模一样)
1.现有三个条件的组合查询界面,提交查询条件(条件分别是:规格,日期1,日期2),对以上两个执行联合查询(分两个SQL语句,分别是SQL1,SQL2)
2.执行代码如下:
sql1="select *,'test1' as 组织 from TEST1 where"
if trim(xxm)<>"" then
sql1=sql1&" 规格 like '%"&trim(xxm)&"%'"
flag=1
end if
if trim(rq)<>"" and flag=1 then
sql1=sql1&" and 日期 >= '"&trim(rq)&"'"
flag=1
else
if trim(rq)<>"" then
sql1=sql1&" 日期 >= '"&trim(rq)&"'"
flag=1
end if
end if
if trim(rq1)<>"" and flag=1 then
sql1=sql1&" and 日期 <='"&trim(rq1)&"'"
flag=1
else
if trim(rq1)<>"" then
sql1=sql1&" 日期 <='"&trim(rq1)&"'"
flag=1
end if
end if
if flag=0 then
sql1="select *,'test1' as 组织 from TEST1"
end if
sql2="select *,'test2' as 组织 from TEST2 where"
if trim(xxm)<>"" then
sql2=sql2&" 规格 like '%"&trim(xxm)&"%'"
flag=1
end if
if trim(rq)<>"" and flag=1 then
sql2=sql2&" and 日期 >= '"&trim(rq)&"'"
flag=1
else
if trim(rq)<>"" then
sql2=sql2&" 日期 >= '"&trim(rq)&"'"
flag=1
end if
end if
if trim(rq1)<>"" and flag=1 then
sql2=sql2&" and 日期 <='"&trim(rq1)&"'"
flag=1
else
if trim(rq1)<>"" then
sql2=sql2&" 日期 <='"&trim(rq1)&"'"
flag=1
end if
end if
if flag=0 then
sql2="select *,'test2' as 组织 from TEST2"
end if
sql=sql1&" union "&sql2
执行不成功,只有把最后一句sql=sql1&" union "&sql2改成SQL=SQL1即只对TEST1查询才成功,改成SQL=SQL2也不成功,难道还分先后顺序?
1.现有三个条件的组合查询界面,提交查询条件(条件分别是:规格,日期1,日期2),对以上两个执行联合查询(分两个SQL语句,分别是SQL1,SQL2)
2.执行代码如下:
sql1="select *,'test1' as 组织 from TEST1 where"
if trim(xxm)<>"" then
sql1=sql1&" 规格 like '%"&trim(xxm)&"%'"
flag=1
end if
if trim(rq)<>"" and flag=1 then
sql1=sql1&" and 日期 >= '"&trim(rq)&"'"
flag=1
else
if trim(rq)<>"" then
sql1=sql1&" 日期 >= '"&trim(rq)&"'"
flag=1
end if
end if
if trim(rq1)<>"" and flag=1 then
sql1=sql1&" and 日期 <='"&trim(rq1)&"'"
flag=1
else
if trim(rq1)<>"" then
sql1=sql1&" 日期 <='"&trim(rq1)&"'"
flag=1
end if
end if
if flag=0 then
sql1="select *,'test1' as 组织 from TEST1"
end if
sql2="select *,'test2' as 组织 from TEST2 where"
if trim(xxm)<>"" then
sql2=sql2&" 规格 like '%"&trim(xxm)&"%'"
flag=1
end if
if trim(rq)<>"" and flag=1 then
sql2=sql2&" and 日期 >= '"&trim(rq)&"'"
flag=1
else
if trim(rq)<>"" then
sql2=sql2&" 日期 >= '"&trim(rq)&"'"
flag=1
end if
end if
if trim(rq1)<>"" and flag=1 then
sql2=sql2&" and 日期 <='"&trim(rq1)&"'"
flag=1
else
if trim(rq1)<>"" then
sql2=sql2&" 日期 <='"&trim(rq1)&"'"
flag=1
end if
end if
if flag=0 then
sql2="select *,'test2' as 组织 from TEST2"
end if
sql=sql1&" union "&sql2
执行不成功,只有把最后一句sql=sql1&" union "&sql2改成SQL=SQL1即只对TEST1查询才成功,改成SQL=SQL2也不成功,难道还分先后顺序?