Link a Query results with a Table

No.of Views685
Bookmarked0 times
Downloads 
Votes0
By  youngmurukan   On  15 Feb 2010 21:02:15
Tag : Sql Servers , T-SQL
Link a Query results with a Table
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 Hi folks,
This is very useful when we use query results with a table.
for example
here i have written query to get the sum of books from one table then i join that query resultset with another table in which i have sum up.

with chequedet(
BCode,NoofLeaves,TTLBooks)
as
(
select BCode,NoofLeaves,sum(NoofBooks) TTLBooks from ChequeDetails
where
JobNo='xxxxxxx'
group by
BCode,NoofLeaves
)
select a.bcode,b.NoofLeaves, b.TTLBooks,sum(a.noofbooks)
from
ChequeDetails a ,chequedet b
where
a.BCode=b.BCode and JobNo='xxxxxxx'
group by a.bcode,b.NoofLeaves,b.TTLBooks
order by a.bcode,b.NoofLeaves, b.TTLBooks

 
Sign Up to vote for this article
 
About Author
 
youngmurukan
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 May 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top