0

Example:

Sql = "Select * From tablo Where Baslik = "&strBaslik&" And Ozellik IN ("&strOzellik&") Order By Id Desc"

I want :

Sql = "Select * From tablo Where Baslik = "&strBaslik&" **IF Not "&strOzellik&" = Then** And Ozellik IN ("&strOzellik&") **End IF** Order By Id Desc"

How do I do this?

Thanks.

1 Answer 1

0

There are several ways to solve this, one of them is to concatenate the sSql query:

<%
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"
%>

Notice that I also added single quotes around your SQL parameters in case the inputs are actually strings. Although, this way is not safe because of SQL injection and you might want to look into parameterized queries.

Sign up to request clarification or add additional context in comments.

1 Comment

@Alp Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.