How to give 2 Conditions in an SQL Query

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 13
Reputation: B.H is an unknown quantity at this point 
Solved Threads: 0
B.H B.H is offline Offline
Newbie Poster

How to give 2 Conditions in an SQL Query

 
0
  #1
Aug 24th, 2006
hi,

My Problem is when am deleting a row from the SQL Server Database....I need to check two conditions.

For eg: While deleting a row from the database,i need to check based upon the Name of the Employee and The Employee Number.

Because there might be Employees with the same Name but differenet Employee Number.

dim sql as string

sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_EmpName.Text.Trim & "'".....// Here can I add one more condition ie Employee Number in the Where clause.

Anyone...please help me.

Thanks lot

Cheers

B.H
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: How to give 2 Conditions in an SQL Query

 
0
  #2
Aug 24th, 2006
Currently:
  1. sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_EmpName.Text.Trim & "'"
Outputs (example employee name = Joe):
sql = "DELETE FROM Employees WHERE Emp_Name='Joe'"

What I think you want:
  1. sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_EmpName.Text.Trim & "' AND Emp_Number=" & Txt_EmpNumber.Trim
Outputs (example employee name (number) = Joe(2)):
sql = "DELETE FROM Employees WHERE Emp_Name='Joe' AND Emp_Number=2"

I'm assuming you have the employee number stored as an integer (or other number type), if it is stored as text you will need to add single quotes around the Txt_EmpNumber.Trim call.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 13
Reputation: B.H is an unknown quantity at this point 
Solved Threads: 0
B.H B.H is offline Offline
Newbie Poster

Re: How to give 2 Conditions in an SQL Query

 
0
  #3
Aug 24th, 2006
I Tried the way u told me...but its showing error....do u have any other idea..thnks bro for replying to my doubt.

if u can help me with any other code that thinks can help me to work out the solution quickly..it would be greatly appreciatable.

Thanks once again for ur help



sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_Name.Text.Trim & "' AND Emp_Number= " & Txt_Empno.Text.Trim & ""
cnn.Execute(sqldelete)
End Sub
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: How to give 2 Conditions in an SQL Query

 
0
  #4
Aug 24th, 2006
As I said, if you have the employee number stored as text, the SQL statement requires single quotes around it. As follows (do not include the double parentheses, they are there to show the difference between '" and "):
sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_Name.Text.Trim & "' AND Emp_Number= (('))" & Txt_Empno.Text.Trim & "(('))"
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 13
Reputation: B.H is an unknown quantity at this point 
Solved Threads: 0
B.H B.H is offline Offline
Newbie Poster

Re: How to give 2 Conditions in an SQL Query

 
0
  #5
Aug 29th, 2006
Thanks bro..urs worked..sorry 4 da late reply.

cheers
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC