I have two different queries:
SELECT 
    PB_BANK_CODE,
    PB_BANK_NAME
FROM GLAS_PDC_BANKS 
WHERE PB_COMP_CODE='1' 
AND PB_BANK_CODE='025' 
AND PB_BANK_CODE IN (
    SELECT DISTINCT PC_BANK_FROM
    FROM GLAS_PDC_CHEQUES 
    WHERE PC_BANK_FROM ='025' 
    AND ISNULL(PC_DISCD,'X') != 'C'
    AND PC_DUE_DATETIME BETWEEN '05/05/2008' AND '05/06/2008'
)
and
SELECT ISNULL(SUM(PC_AMOUNT),0) 
FROM GLAS_PDC_CHEQUES 
WHERE PC_BANK_FROM ='025'
AND ISNULL(PC_DISCD,'X') != 'C'
AND PC_DUE_DATETIME BETWEEN '05/05/2008' AND '05/06/2008' 
I'm trying to merge these two so that I can get PB_BANK_CODE, PB_BANK_NAME, and ISNULL(SUM(PC_AMOUNT),0) in a single dataset.
How can I merge thes开发者_开发知识库e two queries in SQL Server 2005?
You need to make use of two technologies:
- SQL JOIN syntax (look it up in your database documentation, you didn't mention what database you're using)
- The lower case keys on your computer keyboard.
this should do it...
I think?
SELECT 
   PB_BANK_CODE,
   PB_BANK_NAME,
   ISNULL(SUM(PC_AMOUNT),0)
FROM GLAS_PDC_BANKS inner join GLAS_PDC_CHEQUES 
    on GLAS_PDC_BANKS.PB_BANK_CODE = GLAS_PDC_CHEQUES.PC_BANK_FROM
WHERE  PB_COMP_CODE='1' 
   AND PB_BANK_CODE='025' 
   AND ISNULL(PC_DISCD,'X') != 'C'
   AND PC_DUE_DATETIME BETWEEN '05/05/2008' AND '05/06/2008'
If there is a relationship between tables GLAS_PDC_BANKS and GLAS_PDC_CHEQUES then you can just join the two tables and make some small modifications to your query. Without knowing what type of relationship exists between these two tables, I cannot offer a more detailed answer.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论