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 2005 Forums
 Transact-SQL (2005)
 Compare one field against two fields

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-04-09 : 08:03:47
I have a query where I need to compare 1 field against value of 2 fields.

Table 1: Field 1: Value: 01004-AV

Table 2: Field1: Value: 01004 Field 2: Value AV

Sometimes there are no value in Field 2, then need to compare only the Field1's

Thank you

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-04-09 : 08:07:25
SELECT * FROM Table1 T1
INNER JOIN Table2 T2
ON T1.Field1=CASE WHEN T2.Field2 IS NULL THEN T2.Field1 ELSE T2.Field1 + '-' + T2.Field2 END
Go to Top of Page
   

- Advertisement -