1

私は4つの異なるテーブルを持っています

  • アカウント、
  • ブランチ、
  • tblbillers、
  • tblbillerpolicy、

列を含む 4 つのテーブル

  • アカウント (accntID)主キー...
  • ブランチ (branchID)Primary KEY...
  • tblbillers (Billerid) および
  • tblbillerpolicy (PolicyID Primary Key, accountID, BranchID, BIllerID, Enabled, ServiceCharge, MerchantCOmission,PLUCode)

ここで、次のようにテーブル tblbillerpolicy を挿入します。

INSERT INTO dbo.tblbillerpolicy
      ( 

        AccountID                  ,
        BranchID                   ,
        BillerID                   ,
        Enabled                    ,
        ServiceCharge              ,
        MerchantComission          ,
        PLUCode        

      ) 

Select 142, 2171, 2, 'YES', 0.00, 3.50, 'NULL'

UNION ALL

Select 143, 2171, 2, 'YES', 0.00, 3.50, 'NULL'

UNION ALL

Select  143, 2171, 2, 'YES', 0.00, 3.50, 'NULL'

UNION ALL

Select  143, 2171, 2, 'YES', 0.00, 3.50, 'NULL'

where AccountID = accntid <-- for account
and BranchID = branchid <-- for branch
    and BillerID = billerid <-- for tblbillers

今私が本当にしたいのは、この「ONLY」を、上記のテーブル (アカウント、ブランチ、ビラー) に接続された tblbillerpolicy に挿入することです。

4

1 に答える 1

1

クリスチャン・ハーマンCM、

データ ( accountID 142、143 など) を次の条件でテーブルに挿入しますか
?
branch
- billerID (2) はすでに請求書のテーブルにあります


はいの場合は、次のクエリを試してください

INSERT INTO dbo.tblbillerpolicy
  ( 
    AccountID                  ,
    BranchID                   ,
    BillerID                   ,
    Enabled                    ,
    ServiceCharge              ,
    MerchantComission          ,
    PLUCode        
  ) 

select t.* from
(Select AccountID=142, BranchID=2171, BillerID=2, Enabled='YES', ServiceCharge=0.00,  MerchantComission=3.50, PLUCode='NULL'
UNION ALL
Select AccountID=143, BranchID=2171, BillerID=2, Enabled='YES', ServiceCharge=0.00, MerchantComission=3.50, PLUCode='NULL'
UNION ALL
Select  AccountID=143, BranchID=2171, BillerID=2, Enabled='YES', ServiceCharge=0.00, MerchantComission=3.50, PLUCode='NULL'
UNION ALL
Select  AccountID=143, BranchID=2171, BillerID=2, Enabled='YES', ServiceCharge=0.00, MerchantComission=3.50, PLUCode='NULL') t,
account a, branch b, tblbillers tb
where a.AccountID = t.accountID --for account
and b.BranchID = t.BranchID --for branch
and tb.BillerID = t.BillerID --for tblbillers
于 2012-10-18T04:41:49.240 に答える