Guys,

Can you help please to compare or check the records from Mytable1 to MyTable2 if exist or found.
and i have to count the records with not null.
Any idea. you can modify my script.

elect 
	a.ESN
    b.ESN
FROM MyTable1 as a
Left outer join Mytable2 as b
on a.esn = b.esn

Create table MyTable1(ESN varchar(10)
Insert into MyTable1
Value('120')
Value('121')
Value('122')
Value('123')
Value('124')

Create table MyTable2(ESN varchar(10)
Value('120')
Value('121')
Value('122')

The result should be like this:
MyTable
ESN
---------
120--120
121--120
122--120
123--NULL
124--NULL

Thank you guys

Jonel

Recommended Answers

All 2 Replies

Outer join should work for you.

Do you want to count as part of the same select ? Your example result doesn't count.
Anyway, you can count using an outer join.

Since you already have the join written, I'm guessing that you want the results to be in 1 field (like your example result). Then do a select like this:

select table1.ESN + '--' + table2.ESN 
from table1 ....

If you are having problems with NULL (which in the above example will null the whole line) then either use isnull() or SET CONCAT_NULL_YIELDS_NULL OFF (keep in ming that the SET CONCAT_NULL_YIELDS_NULL is being phased out)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.