大家好! 我试图将这个db2代码转换为sql:
CREATE VIEW TBSDB2P.V_ADVICE_SLIPS as select * from ( select AS.AS_NUMBER,AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status, AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, DEP.TENOR, nullif(0,0) Price_Per_100, DEP.FACE_VALUE, nullif(0,0) Number_of_shares, nullif(0,0) Price_per_share, AS.SETTLEMENT_AMOUNT, DEP.RATE, nullif(0,0) YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, AS.COUNTER_PARTY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID FROM TBSDB2P.IMS_AS AS INNER JOIN TBSDB2P.IMS_AS_DEPOSIT DEP on (AS.AS_NUMBER = DEP.AS_NUMBER) LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( DEP.as_number = ALLOC.as_number ) LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER) LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE ) LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE) UNION ALL select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status, AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR, nullif(0,0) Price_Per_100, nullif(0,0) FACE_VALUE, EQT.AWARDED_NUMBER_OF_SHARES, EQT.Price_per_share, AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, nullif(0,0) YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID FROM TBSDB2P.IMS_AS AS INNER JOIN TBSDB2P.IMS_AS_EQUITY EQT on (AS.AS_NUMBER = EQT.AS_NUMBER) LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number ) LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER) LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE ) LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE) UNION ALL select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status, AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR, GS.Price_Per_100, GS.AWARDED_FACE_VALUE as FACE_VALUE, nullif(0,0) Number_of_shares, nullif(0,0) Price_per_share, AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, GS.YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID FROM TBSDB2P.IMS_AS AS INNER JOIN TBSDB2P.IMS_AS_GS GS on (AS.AS_NUMBER = GS.AS_NUMBER) LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number ) LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER) LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE ) LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE) UNION ALL select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status, AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR, nullif(0,0) Price_Per_100, PREF.FACE_VALUE, PREF.DONE_NUMBER_OF_SHARES, PREF.Price_per_share, AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, PREF.YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID FROM TBSDB2P.IMS_AS AS INNER JOIN TBSDB2P.IMS_AS_PREF PREF on ( AS.AS_NUMBER = PREF.AS_NUMBER ) LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number ) LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER) LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE ) LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE) UNION ALL select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status, AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR, nullif(0,0) Price_Per_100, PREP.FACE_VALUE, PREP.AWARDED_NUMBER_OF_SHARES, PREP.Price_per_share, AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, nullif(0,0) YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID FROM TBSDB2P.IMS_AS AS INNER JOIN TBSDB2P.IMS_AS_PREP PREP on ( AS.AS_NUMBER = PREP.AS_NUMBER ) LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number ) LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER) LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE ) LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE) UNION ALL select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status, AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR, OSEC.Price_Per_100, OSEC.AWARDED_FACE_VALUE as FACE_VALUE, nullif(0,0) Number_of_shares, nullif(0,0) Price_per_share, AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, OSEC.YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID FROM TBSDB2P.IMS_AS AS INNER JOIN TBSDB2P.IMS_AS_OSEC OSEC on ( AS.AS_NUMBER = OSEC.AS_NUMBER ) LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number ) LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER) LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE ) LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE) UNION ALL select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status, AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR, nullif(0,0) Price_Per_100, nullif(0,0) FACE_VALUE, PF.AWARDED_NUMBER_OF_UNITS as number_of_shares, nullif(0,0) Price_per_share, AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, nullif(0,0) YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID FROM TBSDB2P.IMS_AS AS INNER JOIN TBSDB2P.IMS_AS_POOLED_FUNDS PF on (AS.AS_NUMBER = PF.AS_NUMBER) LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number ) LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER) LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE ) LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE) ) as ALL_AS;
但它返回一个错误,我的视图的select语句包含子查询。
我试图将它“砍”成单独的select sql语句,这就是我得到的:
select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status,
AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME,
DEP.TENOR, nullif(0,0) Price_Per_100, DEP.FACE_VALUE, nullif(0,0) Number_of_shares, nullif(0,0) Price_per_share,
AS.SETTLEMENT_AMOUNT, DEP.RATE, nullif(0,0) YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER,
AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, AS.COUNTER_PARTY_CODE as ISSUER_CODE,
AS.AS_TYPE, AS.REQ_TBG_UNIT_ID
FROM TBSDB2P.IMS_AS
AS
INNER JOIN TBSDB2P.IMS_AS_DEPOSIT DEP on (TBSDB2P.AS.AS_NUMBER = DEP.AS_NUMBER)
LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( DEP.as_number = ALLOC.as_number )
LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE )
LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status,
AS.Approval_Status, AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE,
ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR, nullif(0,0) Price_Per_100,
nullif(0,0) FACE_VALUE, EQT.AWARDED_NUMBER_OF_SHARES, EQT.Price_per_share, AS.SETTLEMENT_AMOUNT,
nullif(0,0) RATE, nullif(0,0) YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER,
AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID
FROM TBSDB2P.IMS_AS
AS
INNER JOIN TBSDB2P.IMS_AS_EQUITY EQT on (AS.AS_NUMBER = EQT.AS_NUMBER)
LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number )
LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE )
LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status,
AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME,
nullif(0,0) TENOR, GS.Price_Per_100, GS.AWARDED_FACE_VALUE as FACE_VALUE, nullif(0,0) Number_of_shares,
nullif(0,0) Price_per_share, AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, GS.YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER,
AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE,
BANK.REGION_ID, AS.COUNTER_PARTY_CODE, ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID
FROM TBSDB2P.IMS_AS
AS
INNER JOIN TBSDB2P.IMS_AS_GS GS on (AS.AS_NUMBER = GS.AS_NUMBER)
LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number )
LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE )
LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
select
AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status,
AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME,
nullif(0,0) TENOR, nullif(0,0) Price_Per_100, PREF.FACE_VALUE, PREF.DONE_NUMBER_OF_SHARES, PREF.Price_per_share,
AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, PREF.YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER,
ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID
FROM TBSDB2P.IMS_AS
AS
INNER JOIN TBSDB2P.IMS_AS_PREF PREF on ( AS.AS_NUMBER = PREF.AS_NUMBER )
LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number )
LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE )
LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status,
AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME,
nullif(0,0) TENOR, nullif(0,0) Price_Per_100, PREP.FACE_VALUE, PREP.AWARDED_NUMBER_OF_SHARES, PREP.Price_per_share,
AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, nullif(0,0) YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER,
ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID
FROM TBSDB2P.IMS_AS
AS
INNER JOIN TBSDB2P.IMS_AS_PREP PREP on ( AS.AS_NUMBER = PREP.AS_NUMBER )
LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number )
LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE )
LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status,
AS.Transaction_Type, AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR,
OSEC.Price_Per_100, OSEC.AWARDED_FACE_VALUE as FACE_VALUE, nullif(0,0) Number_of_shares, nullif(0,0) Price_per_share,
AS.SETTLEMENT_AMOUNT, nullif(0,0) RATE, OSEC.YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER,
ACCT.ARRANGEMENT, ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE as ISSUER_CODE, AS.AS_TYPE, AS.REQ_TBG_UNIT_ID
FROM TBSDB2P.IMS_AS AS
INNER JOIN TBSDB2P.IMS_AS_OSEC OSEC on ( AS.AS_NUMBER = OSEC.AS_NUMBER )
LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number )
LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE )
LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
select AS.AS_NUMBER, AS.CREATE_TIME_STAMP, AS.ORIGINAL_AS_NUMBER, AS.Record_Status, AS.Approval_Status, AS.Transaction_Type,
AS.Value_Date, AS.ASSET_CLASS_CODE, ACCT.ACCOUNT_NUMBER, ACCT.ACCOUNT_NAME, nullif(0,0) TENOR, nullif(0,0) Price_Per_100,
nullif(0,0) FACE_VALUE, PF.AWARDED_NUMBER_OF_UNITS as number_of_shares, nullif(0,0) Price_per_share, AS.SETTLEMENT_AMOUNT,
nullif(0,0) RATE, nullif(0,0) YTM, AS.ISSUE_CODE, ACCT.USER_ID as ACCOUNT_OFFICER, AS.ACCOUNT_OFFICER as MAKER, ACCT.ARRANGEMENT,
ACCT.PRODUCT_CODE, ACCT.TBG_UNIT_CODE, ACCT.BANK_BRANCH_UNIT_CODE, BANK.REGION_ID, AS.COUNTER_PARTY_CODE, ISSUE.ENTITY_CODE as ISSUER_CODE,
AS.AS_TYPE, AS.REQ_TBG_UNIT_ID
FROM TBSDB2P.IMS_AS
AS
INNER JOIN TBSDB2P.IMS_AS_POOLED_FUNDS PF on (AS.AS_NUMBER = PF.AS_NUMBER)
LEFT JOIN TBSDB2P.IMS_AS_ALLOCATION ALLOC on ( AS.as_number = ALLOC.as_number )
LEFT JOIN TBSDB2P.AMS_ACCOUNT ACCT on (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.TBS_BANK_BRANCH_UNIT BANK on ( ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE )
LEFT JOIN TBSDB2P.TBS_ISSUE ISSUE on (AS.ISSUE_CODE = ISSUE.ISSUE_CODE)
有人会帮我组织这个查询吗?感谢..
答案 0 :(得分:0)
多么怪物!我想我已经明白了。我假设TBSDB2P是一个数据库名称:
CREATE VIEW dbo.V_ADVICE_SLIPS
(
AS_NUMBER,
CREATE_TIME_STAMP,
ORIGINAL_AS_NUMBER,
Record_Status,
Approval_Status,
Transaction_Type,
Value_Date,
ASSET_CLASS_CODE,
ACCOUNT_NUMBER,
ACCOUNT_NAME,
TENOR,
Price_Per_100,
FACE_VALUE,
Number_of_shares,
Price_per_share,
SETTLEMENT_AMOUNT,
RATE,
YTM,
ISSUE_CODE,
ACCOUNT_OFFICER,
MAKER,
ARRANGEMENT,
PRODUCT_CODE,
TBG_UNIT_CODE,
BANK_BRANCH_UNIT_CODE,
REGION_ID,
COUNTER_PARTY_CODE,
COUNTER_PARTY_CODE AS ISSUER_CODE,
AS_TYPE,
REQ_TBG_UNIT_ID
)
AS
SELECT
AS1.AS_NUMBER,
AS1.CREATE_TIME_STAMP,
AS1.ORIGINAL_AS_NUMBER,
AS1.Record_Status,
AS1.Approval_Status,
AS1.Transaction_Type,
AS1.Value_Date,
AS1.ASSET_CLASS_CODE,
ACCT.ACCOUNT_NUMBER,
ACCT.ACCOUNT_NAME,
DEP.TENOR,
NULLIF(0, 0) Price_Per_100,
DEP.FACE_VALUE,
NULLIF(0, 0) Number_of_shares,
NULLIF(0, 0) Price_per_share,
AS1.SETTLEMENT_AMOUNT,
DEP.RATE,
NULLIF(0, 0) YTM,
AS1.ISSUE_CODE,
ACCT.USER_ID AS ACCOUNT_OFFICER,
AS1.ACCOUNT_OFFICER AS MAKER,
ACCT.ARRANGEMENT,
ACCT.PRODUCT_CODE,
ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE,
BANK.REGION_ID,
AS1.COUNTER_PARTY_CODE,
AS1.COUNTER_PARTY_CODE AS ISSUER_CODE,
AS1.AS_TYPE,
AS1.REQ_TBG_UNIT_ID
FROM
TBSDB2P.dbo.IMS_AS AS1
INNER JOIN TBSDB2P.dbo.IMS_AS_DEPOSIT DEP ON (AS1.AS_NUMBER = DEP.AS_NUMBER)
LEFT JOIN TBSDB2P.dbo.IMS_AS_ALLOCATION ALLOC ON (DEP.as_number = ALLOC.as_number)
LEFT JOIN TBSDB2P.dbo.AMS_ACCOUNT ACCT ON (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.dbo.TBS_BANK_BRANCH_UNIT BANK ON (ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE)
LEFT JOIN TBSDB2P.dbo.TBS_ISSUE ISSUE ON (AS1.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
SELECT
AS1.AS_NUMBER,
AS1.CREATE_TIME_STAMP,
AS1.ORIGINAL_AS_NUMBER,
AS1.Record_Status,
AS1.Approval_Status,
AS1.Transaction_Type,
AS1.Value_Date,
AS1.ASSET_CLASS_CODE,
ACCT.ACCOUNT_NUMBER,
ACCT.ACCOUNT_NAME,
NULLIF(0, 0) TENOR,
NULLIF(0, 0) Price_Per_100,
NULLIF(0, 0) FACE_VALUE,
EQT.AWARDED_NUMBER_OF_SHARES,
EQT.Price_per_share,
AS1.SETTLEMENT_AMOUNT,
NULLIF(0, 0) RATE,
NULLIF(0, 0) YTM,
AS1.ISSUE_CODE,
ACCT.USER_ID AS ACCOUNT_OFFICER,
AS1.ACCOUNT_OFFICER AS MAKER,
ACCT.ARRANGEMENT,
ACCT.PRODUCT_CODE,
ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE,
BANK.REGION_ID,
AS1.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE AS ISSUER_CODE,
AS1.AS_TYPE,
AS1.REQ_TBG_UNIT_ID
FROM
TBSDB2P.dbo.IMS_AS AS1
INNER JOIN TBSDB2P.dbo.IMS_AS_EQUITY EQT ON (AS1.AS_NUMBER = EQT.AS_NUMBER)
LEFT JOIN TBSDB2P.dbo.IMS_AS_ALLOCATION ALLOC ON (AS1.as_number = ALLOC.as_number)
LEFT JOIN TBSDB2P.dbo.AMS_ACCOUNT ACCT ON (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.dbo.TBS_BANK_BRANCH_UNIT BANK ON (ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE)
LEFT JOIN TBSDB2P.dbo.TBS_ISSUE ISSUE ON (AS1.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
SELECT
AS1.AS_NUMBER,
AS1.CREATE_TIME_STAMP,
AS1.ORIGINAL_AS_NUMBER,
AS1.Record_Status,
AS1.Approval_Status,
AS1.Transaction_Type,
AS1.Value_Date,
AS1.ASSET_CLASS_CODE,
ACCT.ACCOUNT_NUMBER,
ACCT.ACCOUNT_NAME,
NULLIF(0, 0) TENOR,
GS.Price_Per_100,
GS.AWARDED_FACE_VALUE AS FACE_VALUE,
NULLIF(0, 0) Number_of_shares,
NULLIF(0, 0) Price_per_share,
AS1.SETTLEMENT_AMOUNT,
NULLIF(0, 0) RATE,
GS.YTM,
AS1.ISSUE_CODE,
ACCT.USER_ID AS ACCOUNT_OFFICER,
AS1.ACCOUNT_OFFICER AS MAKER,
ACCT.ARRANGEMENT,
ACCT.PRODUCT_CODE,
ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE,
BANK.REGION_ID,
AS1.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE AS ISSUER_CODE,
AS1.AS_TYPE,
AS1.REQ_TBG_UNIT_ID
FROM
TBSDB2P.dbo.IMS_AS AS1
INNER JOIN TBSDB2P.dbo.IMS_AS_GS GS ON (AS1.AS_NUMBER = GS.AS_NUMBER)
LEFT JOIN TBSDB2P.dbo.IMS_AS_ALLOCATION ALLOC ON (AS1.as_number = ALLOC.as_number)
LEFT JOIN TBSDB2P.dbo.AMS_ACCOUNT ACCT ON (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.dbo.TBS_BANK_BRANCH_UNIT BANK ON (ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE)
LEFT JOIN TBSDB2P.dbo.TBS_ISSUE ISSUE ON (AS1.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
SELECT
AS1.AS_NUMBER,
AS1.CREATE_TIME_STAMP,
AS1.ORIGINAL_AS_NUMBER,
AS1.Record_Status,
AS1.Approval_Status,
AS1.Transaction_Type,
AS1.Value_Date,
AS1.ASSET_CLASS_CODE,
ACCT.ACCOUNT_NUMBER,
ACCT.ACCOUNT_NAME,
NULLIF(0, 0) TENOR,
NULLIF(0, 0) Price_Per_100,
PREF.FACE_VALUE,
PREF.DONE_NUMBER_OF_SHARES,
PREF.Price_per_share,
AS1.SETTLEMENT_AMOUNT,
NULLIF(0, 0) RATE,
PREF.YTM,
AS1.ISSUE_CODE,
ACCT.USER_ID AS ACCOUNT_OFFICER,
AS1.ACCOUNT_OFFICER AS MAKER,
ACCT.ARRANGEMENT,
ACCT.PRODUCT_CODE,
ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE,
BANK.REGION_ID,
AS1.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE AS ISSUER_CODE,
AS1.AS_TYPE,
AS1.REQ_TBG_UNIT_ID
FROM
TBSDB2P.dbo.IMS_AS AS1
INNER JOIN TBSDB2P.dbo.IMS_AS_PREF PREF ON (AS1.AS_NUMBER = PREF.AS_NUMBER)
LEFT JOIN TBSDB2P.dbo.IMS_AS_ALLOCATION ALLOC ON (AS1.as_number = ALLOC.as_number)
LEFT JOIN TBSDB2P.dbo.AMS_ACCOUNT ACCT ON (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.dbo.TBS_BANK_BRANCH_UNIT BANK ON (ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE)
LEFT JOIN TBSDB2P.dbo.TBS_ISSUE ISSUE ON (AS1.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
SELECT
AS1.AS_NUMBER,
AS1.CREATE_TIME_STAMP,
AS1.ORIGINAL_AS_NUMBER,
AS1.Record_Status,
AS1.Approval_Status,
AS1.Transaction_Type,
AS1.Value_Date,
AS1.ASSET_CLASS_CODE,
ACCT.ACCOUNT_NUMBER,
ACCT.ACCOUNT_NAME,
NULLIF(0, 0) TENOR,
NULLIF(0, 0) Price_Per_100,
PREP.FACE_VALUE,
PREP.AWARDED_NUMBER_OF_SHARES,
PREP.Price_per_share,
AS1.SETTLEMENT_AMOUNT,
NULLIF(0, 0) RATE,
NULLIF(0, 0) YTM,
AS1.ISSUE_CODE,
ACCT.USER_ID AS ACCOUNT_OFFICER,
AS1.ACCOUNT_OFFICER AS MAKER,
ACCT.ARRANGEMENT,
ACCT.PRODUCT_CODE,
ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE,
BANK.REGION_ID,
AS1.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE AS ISSUER_CODE,
AS1.AS_TYPE,
AS1.REQ_TBG_UNIT_ID
FROM
TBSDB2P.dbo.IMS_AS AS1
INNER JOIN TBSDB2P.dbo.IMS_AS_PREP PREP ON (AS1.AS_NUMBER = PREP.AS_NUMBER)
LEFT JOIN TBSDB2P.dbo.IMS_AS_ALLOCATION ALLOC ON (AS1.as_number = ALLOC.as_number)
LEFT JOIN TBSDB2P.dbo.AMS_ACCOUNT ACCT ON (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.dbo.TBS_BANK_BRANCH_UNIT BANK ON (ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE)
LEFT JOIN TBSDB2P.dbo.TBS_ISSUE ISSUE ON (AS1.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
SELECT
AS1.AS_NUMBER,
AS1.CREATE_TIME_STAMP,
AS1.ORIGINAL_AS_NUMBER,
AS1.Record_Status,
AS1.Approval_Status,
AS1.Transaction_Type,
AS1.Value_Date,
AS1.ASSET_CLASS_CODE,
ACCT.ACCOUNT_NUMBER,
ACCT.ACCOUNT_NAME,
NULLIF(0, 0) TENOR,
OSEC.Price_Per_100,
OSEC.AWARDED_FACE_VALUE AS FACE_VALUE,
NULLIF(0, 0) Number_of_shares,
NULLIF(0, 0) Price_per_share,
AS1.SETTLEMENT_AMOUNT,
NULLIF(0, 0) RATE,
OSEC.YTM,
AS1.ISSUE_CODE,
ACCT.USER_ID AS ACCOUNT_OFFICER,
AS1.ACCOUNT_OFFICER AS MAKER,
ACCT.ARRANGEMENT,
ACCT.PRODUCT_CODE,
ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE,
BANK.REGION_ID,
AS1.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE AS ISSUER_CODE,
AS1.AS_TYPE,
AS1.REQ_TBG_UNIT_ID
FROM
TBSDB2P.dbo.IMS_AS AS1
INNER JOIN TBSDB2P.dbo.IMS_AS_OSEC OSEC ON (AS1.AS_NUMBER = OSEC.AS_NUMBER)
LEFT JOIN TBSDB2P.dbo.IMS_AS_ALLOCATION ALLOC ON (AS1.as_number = ALLOC.as_number)
LEFT JOIN TBSDB2P.dbo.AMS_ACCOUNT ACCT ON (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.dbo.TBS_BANK_BRANCH_UNIT BANK ON (ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE)
LEFT JOIN TBSDB2P.dbo.TBS_ISSUE ISSUE ON (AS1.ISSUE_CODE = ISSUE.ISSUE_CODE)
UNION ALL
SELECT
AS1.AS_NUMBER,
AS1.CREATE_TIME_STAMP,
AS1.ORIGINAL_AS_NUMBER,
AS1.Record_Status,
AS1.Approval_Status,
AS1.Transaction_Type,
AS1.Value_Date,
AS1.ASSET_CLASS_CODE,
ACCT.ACCOUNT_NUMBER,
ACCT.ACCOUNT_NAME,
NULLIF(0, 0) TENOR,
NULLIF(0, 0) Price_Per_100,
NULLIF(0, 0) FACE_VALUE,
PF.AWARDED_NUMBER_OF_UNITS AS number_of_shares,
NULLIF(0, 0) Price_per_share,
AS1.SETTLEMENT_AMOUNT,
NULLIF(0, 0) RATE,
NULLIF(0, 0) YTM,
AS1.ISSUE_CODE,
ACCT.USER_ID AS ACCOUNT_OFFICER,
AS1.ACCOUNT_OFFICER AS MAKER,
ACCT.ARRANGEMENT,
ACCT.PRODUCT_CODE,
ACCT.TBG_UNIT_CODE,
ACCT.BANK_BRANCH_UNIT_CODE,
BANK.REGION_ID,
AS1.COUNTER_PARTY_CODE,
ISSUE.ENTITY_CODE AS ISSUER_CODE,
AS1.AS_TYPE,
AS1.REQ_TBG_UNIT_ID
FROM
TBSDB2P.dbo.IMS_AS AS1
INNER JOIN TBSDB2P.dbo.IMS_AS_POOLED_FUNDS PF ON (AS1.AS_NUMBER = PF.AS_NUMBER)
LEFT JOIN TBSDB2P.dbo.IMS_AS_ALLOCATION ALLOC ON (AS1.as_number = ALLOC.as_number)
LEFT JOIN TBSDB2P.dbo.AMS_ACCOUNT ACCT ON (ALLOC.Account_number = ACCT.ACCOUNT_NUMBER)
LEFT JOIN TBSDB2P.dbo.TBS_BANK_BRANCH_UNIT BANK ON (ACCT.BANK_BRANCH_UNIT_CODE = BANK.BANK_BRANCH_UNIT_CODE)
LEFT JOIN TBSDB2P.dbo.TBS_ISSUE ISSUE ON (AS1.ISSUE_CODE = ISSUE.ISSUE_CODE)
GO;