C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Merging tables


Posted Date: 07 Nov 2009      Posted By: dom      Member Level: Silver     Points: 1   Responses: 1



SELECT
PB_BANK_CODE,
PB_BANK_NAME,
FROM GLAS_PDC_BANKS
WHERE PB_COMP_CODE=@COMP_CODE AND PB_BANK_CODE IN
(SELECT DISTINCT PC_BANK_FROM FROM GLAS_PDC_CHEQUES WHERE
PC_COMP_CODE=@COMP_CODE AND PC_DUE_DATETIME BETWEEN @DATE_FROM AND @DATE_TO AND ISNULL(PC_DISCD,'X') = 'R')
ORDER BY PB_BANK_CODE


TOTAL AMOUNT:


SELECT SUM(PC_AMOUNT) as total
FROM GLAS_PDC_CHEQUES
WHERE PC_DUE_DATE BETWEEN :BLOCK01.DATE_FROM AND :BLOCK01.DATE_TO
AND PC_BANK_FROM = :BLOCK02.PB_BANK_CODE
AND NVL(PC_DISCD, 'X') = 'R';







How can i merge the above two queries





Responses

Author: vipul    07 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hi,
i think...you can't marge this two query if you used union then it is required all the column same in the both query. so you can't marge this two query but you can do this way

SELECT
PB_BANK_CODE,
PB_BANK_NAME,
FROM GLAS_PDC_BANKS,
(
SELECT SUM(PC_AMOUNT)
FROM GLAS_PDC_CHEQUES
WHERE PC_DUE_DATE BETWEEN :BLOCK01.DATE_FROM AND :BLOCK01.DATE_TO
AND PC_BANK_FROM = :BLOCK02.PB_BANK_CODE
AND NVL(PC_DISCD, 'X') = 'R'
) as total
WHERE PB_COMP_CODE=@COMP_CODE AND PB_BANK_CODE IN
(SELECT DISTINCT PC_BANK_FROM FROM GLAS_PDC_CHEQUES WHERE
PC_COMP_CODE=@COMP_CODE AND PC_DUE_DATETIME BETWEEN @DATE_FROM AND @DATE_TO AND ISNULL(PC_DISCD,'X') = 'R')
ORDER BY PB_BANK_CODE


Please Rate This Answer If They Helpful

Thanks & Regards
Patel Vipul



Post Reply
You must Sign In to post a response.
Next : Cursor,index
Previous : Update Query
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use