Start New Discussion Reply to this Discussion How to give 2 Conditions in an SQL Query
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
Related Article: need help
is a VB.NET discussion thread by gentleman4u that has 8 replies and was last updated 6 years ago.
B.H
Newbie Poster
13 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Currently:
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:
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.
DavidRyan
Posting Whiz in Training
229 posts since Jul 2006
Reputation Points: 22
Solved Threads: 12
Skill Endorsements: 0
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
B.H
Newbie Poster
13 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
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 & "(('))"
DavidRyan
Posting Whiz in Training
229 posts since Jul 2006
Reputation Points: 22
Solved Threads: 12
Skill Endorsements: 0
Thanks bro..urs worked..sorry 4 da late reply.
cheers
B.H
Newbie Poster
13 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0832 seconds
using 2.65MB