Solved

If statement in SQL Query

Posted on 2014-03-13
4
273 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Button on Table, name table1 not working 4 33
ASP and Looping Thru a XML Document 4 28
Asp response.write to clients 6 33
Union & Crosstab qrys 101! 6 55
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

763 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