Click here to Skip to main content
15,914,350 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
SQL
SqlCommand cmd = new SqlCommand("SELECT * FROM SendP WHERE Emp_Id = Email);



comparing two fields in one table. example: if two fields are equal that means given values. condition is success other wise fail. in need how to write command in sql or stored procedure
Posted
Updated 22-May-12 2:16am
v3
Comments
Prasad_Kulkarni 22-May-12 8:12am    
..and your question is?
Zoltán Zörgő 27-May-12 13:35pm    
Any progress?

Please clarify your question.
If you want to fetch those records that Emp_Id and Email is same,
the your query is right.

SQL
SELECT * FROM tablename WHERE col1= col2
 
Share this answer
 
Or do you mean that you want to compare two different fields with different values. So something like?
SQL
select *
from   yourtable
where  column1 = 'A'
and    column2 = 'B'
 
Share this answer
 
If you want to return a predefined value based on the equality of two fields in a row, you have to use case statements like this:

SQL
select case when Emp_Id = Email then 'equals' else 'not equals' end from SendP
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900