在一个表中比较两个字段 [英] compare two fields in one table

查看:104
本文介绍了在一个表中比较两个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlCommand cmd = new SqlCommand("SELECT * FROM SendP WHERE Emp_Id = Email);




比较一张表中的两个字段.示例:如果两个字段相等,则表示给定值.条件是成功,否则失败.需要如何在sql或存储过程中编写命令的方法




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

推荐答案

请澄清您的问题.
如果要获取Emp_Id和Email相同的那些记录,
您的查询是正确的.

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

SELECT * FROM tablename WHERE col1= col2


还是您要比较两个具有不同值的不同字段.像这样吗?
Or do you mean that you want to compare two different fields with different values. So something like?
select *
from   yourtable
where  column1 = 'A'
and    column2 = 'B'


如果要基于连续两个字段的相等性返回预定义值,则必须使用如下case语句:

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:

select case when Emp_Id = Email then 'equals' else 'not equals' end from SendP


这篇关于在一个表中比较两个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆