How to find missed data from a table by comparing two columns?

#Temp table

Yearmody     Presentdata   PreviousData
20130317        236575
20130310        205379         205379
20130303        286207         286207
20130224        249361         249361
20130217        224401         224401
20130210        171052         171052
20130203        null               204978
20130127       199835          199835
20130120       null               190591
20130113       171052           171052


I got the above data from left joining two tables but i want to find in which yearmoday the data was missing by comparing the presentdata column with previousdata column.

Guys can you please help me how can i do this please
GreatLakes07Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
Sorry, not sure I understand clearly. Could you identify the 'expected result' from that sample? Then we can be sure.
0
GreatLakes07Author Commented:
I want to find in which column the data is null
example from the aboove temp table
20130203
20130120
0
chaauCommented:
If you are only interested in missing PresentData, the query will be:
SELECT Yearmody  from #Temp where PresentData IS NULL

Open in new window

If you are interested in both Present and Previous data, the query will be:
SELECT Yearmody  from #Temp where PresentData IS NULL OR PreviousData IS NULL

Open in new window

If you are interested records for which Present and Previous data are different, the query will be:
SELECT Yearmody  from #Temp where PresentData <> PreviousData

Open in new window

0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Koen Van WielinkBusiness Intelligence SpecialistCommented:
Add a line in your "Where" clause:

Where yourtable.PresentData IS NULL

Open in new window

0
Koen Van WielinkBusiness Intelligence SpecialistCommented:
Hahaha, beaten by 11 seconds!
Please award points to Chaau only, his answer is way more comprehensive than mine.
0
GreatLakes07Author Commented:
Awesome buddies you are Brilliants but
if there are nulls i want to print them are also i want to print temp table
How to scan the column whenther nulls are present or not??
0
chaauCommented:
What do you mean by "print"?
0
GreatLakes07Author Commented:
Sorry not print select * from #Temp table (if null are not there in temp table)
if nulls are there i need to select where null are there in temp table
0
chaauCommented:
There, not there....
This will select where NULL is there:
SELECT Yearmody, PresentData, PreviousData  from #Temp where PresentData IS NULL

Open in new window

This will select where NULL is not there:
SELECT Yearmody, PresentData, PreviousData  from #Temp where PresentData IS NOT NULL

Open in new window

This will select all:
SELECT Yearmody, PresentData, PreviousData  from #Temp

Open in new window

0
GreatLakes07Author Commented:
Yes all the statements must be in stored Proc edure
can we set all three statements using any IF condidtion if possible???
0
PortletPaulfreelancerCommented:
If I may observe, in your sample data there are 2 entries of NULL, but another row shows something else (actually nothing is shown), could that indicate an "empty string"?

The columns appear to be |date|int|int| is that true? or are any of these (n)varchar?

Yearmody     Presentdata   PreviousData
20130317        236575                                 --<< "empty string"????
..
20130203        null               204978            --<< null is identified
..
20130120       null               190591            --<< null is identified
..
0
chaauCommented:
Yes, you can have three of them in a stored procedure. You would have to pass a parameter, called e.g. @Option, that will take three values: 1 - Show only NULLs, 2 - Show NOT NULLs, 3 - Show All. Then you have multiple choice: you can either use IF ... THEN, or you can write everything within a single SQL statement:
SELECT Yearmody, PresentData, PreviousData  
from #Temp 
where @Option = 2 AND PresentData IS NOT NULL
OR @Option = 1 AND PresentData IS NULL
OR @Option = 3

Open in new window

0
GreatLakes07Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for GreatLakes07's comment #a39520050

for the following reason:

impressive and good
0
Koen Van WielinkBusiness Intelligence SpecialistCommented:
If the user decides this question should be closed, points should be awarded to Chaau as based on how the question was formulated he provided a correct and comprehensive answer. If it doesn't solve the asker's problem he/she should state so instead of requesting that the question be closed without awarding any points.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GreatLakes07Author Commented:
good
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.