Solved

If statement in SQL Query

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Email Header Detail 12 63
Separate 2 comma delimited columns into separate rows 2 40
If condition on Html with Asp 11 27
Access join syntax when converting to T-SQL query 4 32
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

791 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