Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Comparision

Author  Topic 

rintus
Starting Member

26 Posts

Posted - 2008-09-04 : 14:21:33
Suppose I have two tables and I want to select certain attributes and want to compare two of the attributes and generate another column in the result set if the attributes are equal than no and if not than yes. For example -
select a.name,
a.roll_no,
b.name,
b.subject from a, b
where a.row_id = b.row_id

I want to compare if a.name <> b.name than 'Yes' else 'No' and this result should be displayed in the result set of the select statement above.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-04 : 14:29:06
[code]select a.name,
a.roll_no,
b.name,
b.subject,
case when a.name <> b.name then 'Yes' else 'No' end as yourcolumnname
from a
join b
on a.row_id = b.row_id[/code]
Go to Top of Page

rintus
Starting Member

26 Posts

Posted - 2008-09-04 : 14:43:47
Thanks a lot :)
Go to Top of Page
   

- Advertisement -