要发挥创造力潜能:怎么在SQL语句中插入一个变量?让SQL语句变的灵活多变.

来源:百度文库 编辑:高考问答 时间:2024/04/29 06:12:32
类似于下面的做法,但是我知道我写的是错的,应该怎么写?

dim bianliang
if request("action")="qiulei" then bianliang="gq=1"
if request("action")="gonglei" then bianliang="gq=0"

rs.open "select * from gqxx where yz=1 and 'bianliang' order by id desc",conn,1,1

楼上的有点笔误

s.open "select * from gqxx where yz=1 and gq='" & bianliang & "' order by id desc", conn, 1, 1

注意 gq=' ,后面有个单引号。后面的 ' order 也是。

dim bianliang
if request("action")="qiulei" then bianliang=1
if request("action")="gonglei" then bianliang=0

rs.open "select * from gqxx where yz=1 and gq="&bianliang&" order by id desc",conn,1,1

dim bianliang
if request("action")="qiulei" then
sql="select * from gqxx where yz=1 and gq=1 order by id desc"
elseif request("action")="gonglei" then
sql="select * from gqxx where yz=0 and gq=0 order by id desc"
end if
rs.open sql,conn,1,1
你应该是这样的意思!