Solved

If statement in SQL Query

Posted on 2014-03-13
4
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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