示例:
Sql = "Select * From tablo Where Baslik = "&strBaslik&" And Ozellik IN ("&strOzellik&") Order By Id Desc"
我想要:
Sql = "Select * From tablo Where Baslik = "&strBaslik&" **IF Not "&strOzellik&" = Then** And Ozellik IN ("&strOzellik&") **End IF** Order By Id Desc"
我该怎么做?
谢谢。
最佳答案
有多种方法可以解决这个问题,其中之一是连接 sSql 查询:
<%
sSql = "Select * From tablo Where Baslik = '"& strBaslik & "' "
If Not strOzellik = "???" Then
sSql = sSql & " And Ozellik IN ('" & strOzellik & "')"
End If
sSql = sSql & " Order By Id Desc"
%>
请注意,我还在 SQL 参数周围添加了单引号,以防输入实际上是字符串。不过,由于 SQL 注入(inject),这种方式并不安全,您可能需要查看 parameterized queries .
关于MySQL 查询 + ASP IF Else End IF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28678786/