Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

If statement in SQL Query

Posted on 2014-03-13
4
Medium Priority
?
305 Views
Last Modified: 2014-03-13
Hi Experts,
How could I place the If statement below in the where clause of an SQL query?

WHERE Emp_Id = <%If not rs1.EOF or NOT rs1.BOF Then Response.Write(rs1("Emp_Id")) Else Response.Write (Emp_Id) End If%>

I would appreciate your help.
0
Comment
Question by:romsom
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39927960
Without any context...

If not rs1.EOF or NOT rs1.BOF Then Emp_Id = rs1("Emp_Id")

"SELECT
...
WHERE Emp_Id =" & Emp_Id

Open in new window

0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 39927963
Any more context you can provide?  I try not to dynamically insert items into the SQL string like that.  

If there is only expected to be a single variable in that recordset, then why not just load the contents of that recordset into an ASP variable and put that in there.  

Perhaps if we could see some more code around this, including how you are getting the recordset data, we could probably optimize this code some more.
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 39927964
I see Gary tossed a comment in there while I was typing my response.  I agree with his code without any context.
0
 

Author Closing Comment

by:romsom
ID: 39927969
This is perfect, thank you very much!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question