Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to perform two operations i.e, INNER JOIN and use of WHERE clauses simultaneously in single query:
first one is for Inner join another is for Where clause:-
SQL
SELECT rpd.registration_no,rpd.name, rpd.marriage_anniversary_date,fd.name
FROM rpd
INNER JOIN fd
ON rpd.registration_no=fd.registration_no and rpd.marriage_anniversary_date=fd.marriage_anniversary_date


SQL
SELECT registration_no,name, marriage_anniversary_date
FROM rpd WHERE ((DATEDIFF(dd, getdate(), DATEADD(yyyy, DATEDIFF(yyyy, marriage_anniversary_date, getdate()) + 1, marriage_anniversary_date))) % 366 <= 10) order by marriage_anniversary_date desc

This is for fetching birthdays in next 10 days.

I want to make one single query for both...
Posted
Updated 10-Dec-15 23:22pm
v2

1 solution

So do:
SQL
SELECT rpd.registration_no,rpd.name, rpd.marriage_anniversary_date,fd.name
FROM rpd
INNER JOIN fd
ON rpd.registration_no=fd.registration_no and rpd.marriage_anniversary_date=fd.marriage_anniversary_date
WHERE ((DATEDIFF(dd, getdate(), DATEADD(yyyy, DATEDIFF(yyyy, rpd.marriage_anniversary_date, getdate()) + 1, rpd.marriage_anniversary_date))) % 366 <= 10) 
ORDER BY rpd.marriage_anniversary_date DESC

Was that so difficult?
 
Share this answer
 
Comments
Member 12133159 11-Dec-15 5:58am    
Thanks OriginalGriff...
I tried this but due to some little mistake it was not working at that time...
Thanks Again... :)
OriginalGriff 11-Dec-15 6:02am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900