Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two tables containing same fields in database.
One table will contain data..
2nd table will contain data which are changed in table 1..SRNO is same in table 1 and table 2
Now I want a report based on date.
How to check for the date selected in both tables and get report for the selected date?
Posted
Comments
Prasad Khandekar 1-Jul-13 9:39am    
Hello Rachna,

You can use INNER JOIN Query to fetch data from both the tables. Based on your inputs the JOIN will be on the SRNO column. The query in your case might look like the one shown below.

SELECT t1.*
FROM table1 AS t1
INNER JOIN table2 AS t2
ON t2.srno = t1.srno
WHERE t1.data = YYYYMMDD.

Please have a look at following MSDN Link to know more about date literals. (http://msdn.microsoft.com/en-us/library/ms187819.aspx)

Regards,
ZurdoDev 1-Jul-13 9:58am    
Where are you stuck?
Maciej Los 1-Jul-13 11:36am    
We need example data and expected output. Use "Improve question" widget.

Suppose You have two table i.e. table1 and table2 the query will be as below
SQL
SELECT t1.srNo,t1.Data as OLDData,t2.Data as ChangeData  
FROM table1 AS t1
   INNER JOIN table2 AS t2
     ON t2.srno = t1.srno
WHERE t1.date = YYYYMMDD or t2.date=YYYYMMDD.
 
Share this answer
 
Suppose You have two table i.e. table1 and table2 the query will be as below

SELECT t1.srNo,t1.Data as OLDData,t2.Data as ChangeData
FROM table1 AS t1
INNER JOIN table2 AS t2
ON t2.srno = t1.srno
WHERE t1.date = YYYYMMDD or t2.date=YYYYMMDD.
 
Share this answer
 
Comments
Maciej Los 1-Jul-13 15:43pm    
Do not repost the same answer! Please, remove it to avoid down-voting.

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