如何在SQL中创建动态表

时间:2019-12-25 00:01:31

标签: sql sql-server

我有两个表A,B,并且创建了视图以使A与B一致(如下所示)。我的问题是想要与A协调具有相同列和不同数据的其他表。我该怎么做?

表A

CONTRACT_NUMBER CCY     CCY AMOUNT
224564298501    EUR     24020264.00
225835039771    EUR     10000000.00
225965084231    EUR     10000000.00

表B

CONTRACT        CURRENCY        amount
224564298501    EUR          24020264.00
225835039771    EUR          10000000.00
225965084231    EUR          10000000.00

将B与A调和

IF OBJECT_ID('B_recon', 'v') IS NOT NULL 
  DROP VIEW [B_recon] ; 
GO

CREATE VIEW [B_recon] AS
     SELECT 
        -- AMOUNT and contract number
        ,A.[CONTRACT_NUMBER]
        ,B.[CONTRACT]
        ,A.[CCY AMOUNT]
        ,B.[amount]

        ,CASE 
            WHEN [CCY AMOUNT] = [amount] 
                THEN 'True'
                ELSE 'False'
            END AS AMOUNT_RECO
     FROM 
        [A]
     LEFT  JOIN 
        [B]  
        ON 
            A.[CONTRACT_NUMBER] = B.[CONTRACT]


    GO 

SELECT * FROM [AB_recon]

0 个答案:

没有答案