Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SELECT
[NewspaperName]
,[AreaOfNews]
,[RateOfNewsPublished]
,[TotalAmount]

FROM [ecampus].[dbo].[tblDailyNewsPublishedDetails] WHERE NewspaperName='AAPALA SARVMAT' AND DateOfPublication BETWEEN '2016-09-28' AND '2016-10-05'





SELECT [NewspaperName]
,[AreaOfAdvertisement]
,[RatePerSqCm]
,[TotalAmount]
,[Discount]
,[ActualAmountPaid]
FROM [ecampus].[dbo].[tblAdvertisementRequestDetails] WHERE NewspaperName='AAPALA SARVMAT' AND DateOfPublication BETWEEN '2016-09-28' AND '2016-10-05' and [AdvertisementPublishStatus]='Y'

What I have tried:

Please reply I want to perform join on above queries so i will make comparison in my project about advertisement published and news published
Posted
Updated 5-Oct-16 23:22pm

1 solution

Start by changing your DB: add a third table
Newspapers
C#
ID        INT, IDENTITY, PRIMARY KEY
PaperName NVARCHAR
And then get rid of your string based NewpaperName from your other tables in favor of a FOREIGN KEY to the ID field of the Newspapers table.
You can then use a join to get the name:
SQL
SELECT n.PaperName, npd.AreaOfNews FROM tblDailyNewsPublishedDetails npd
JOIN Newspapers n ON n.ID = npd.PaperID
That's a lot more efficient than storeing teh paper name each time.
Then you can add to the JOIN:
SQL
SELECT n.PaperName, npd.AreaOfNews, ard.AreaOfAdvertisment FROM tblDailyNewsPublishedDetails npd
JOIN Newspapers n ON n.ID = npd.PaperID
JOIN tblAdvertisementRequestDetails ard ON n.ID = ard.PaperID AND ard.DateOfPublication = npd.DateOfPublication
WHERE ard.DateOfPublication BETWEEN '2016-09-28' AND '2016-10-05' and ard.AdvertisementPublishStatus='Y'
Which will probably give you the start of what you want.
 
Share this answer
 

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