Помогите пожалуйсто объеденить между собой запросы
Есть запрос 1:
| Код | Select RupayUser.RupayUserId, dbo.RupayUser.BirthDate From dbo.RupayUser inner join dbo.Account on dbo.Account.AccountId = RupayUser.RupayUserId
|
Есть запрос 2:
| Код | Select top 100 * from (select Account.AccountId ,Account.AmountCurrency ,Account.CreationDate ,legal_LegalEntity.Name ,legal_LegalEntity.FullName ,legal_LegalEntity.Fax ,legal_LegalEntity.Phone ,legal_LegalEntity.SiteUrl ,legal_LegalEntity.Inn ,legal_LegalEntity.Kpp ,legal_LegalEntity.LegalAddress ,legal_LegalEntity.MobilePhone ,legal_LegalEntity.Ogrn ,legal_LegalEntity.Okpo ,legal_Contract.ContractId ,legal_Contract.ContractNumber ,legal_Contract.ContractDate ,legal_LegalEntity.BankId ,legal_LegalEntity.SettleAccount ,legal_Bank.NEWNUM ,legal_Bank.KSNP ,legal_LegalEntity.LegalAddress as LegalAddressYurik ,legal_LegalEntity.RealAddress as RealAddressYurik ,legal_LegalEntity.LegalEntityId ,fizik_goga = case when legal_LegalEntity.LegalEntityId is not NULL then 'yurik' else 'fizik' end , organization = case when Account.CompanyTransferDate is null then 'RM' else 'DP' end from Account inner join acc_RupayAccount on Account.AccountId = acc_RupayAccount.RupayAccountId left join dbo.RupayUser on RupayUser.RupayUserId = acc_RupayAccount.RupayUserId left join dbo.legal_LegalEntity on legal_LegalEntity.RupayUserId = RupayUser.RupayUserId left join dbo.legal_Contract on legal_LegalEntity.ContractId = legal_Contract.ContractId left join dbo.legal_Bank on legal_Bank.BankId = legal_LegalEntity.BankId union all -- СКО select Account.AccountId ,Account.AmountCurrency ,Account.CreationDate ,'' as Name ,'' as FullName ,'' as Fax ,'' as Phone ,'' as SiteUrl ,'' as Inn ,'' as Kpp ,'' as LegalAddress ,'' as MobilePhone ,'' as Ogrn ,'' as Okpo ,'' as ContractId ,'' as ContractNumber ,'' as ContractDate ,'' as BankId ,'' AS SettleAccount ,'' AS NEWNUM ,'' as KSNP ,'' as LegalAddressYurik ,'' as RealAddressYurik ,'' as LegalEntityId ,'SKO' as fizik_goga , organization = case when Account.CompanyTransferDate is null then 'RM' else 'DP' end from Account inner join dbo.acc_InvoiceAccount on dbo.acc_InvoiceAccount.InvoiceAccountId = Account.AccountId ) as Tab
|
а если вместе сделать вот так:
| Код | Select top 100 * from (select Account.AccountId ,Account.AmountCurrency ,Account.CreationDate ,legal_LegalEntity.Name ,legal_LegalEntity.FullName ,legal_LegalEntity.Fax ,legal_LegalEntity.Phone ,legal_LegalEntity.SiteUrl ,legal_LegalEntity.Inn ,legal_LegalEntity.Kpp ,legal_LegalEntity.LegalAddress ,legal_LegalEntity.MobilePhone ,legal_LegalEntity.Ogrn ,legal_LegalEntity.Okpo ,legal_Contract.ContractId ,legal_Contract.ContractNumber ,legal_Contract.ContractDate ,legal_LegalEntity.BankId ,legal_LegalEntity.SettleAccount ,legal_Bank.NEWNUM ,legal_Bank.KSNP ,legal_LegalEntity.LegalAddress as LegalAddressYurik ,legal_LegalEntity.RealAddress as RealAddressYurik ,legal_LegalEntity.LegalEntityId ,fizik_goga = case when legal_LegalEntity.LegalEntityId is not NULL then 'yurik' else 'fizik' end , organization = case when Account.CompanyTransferDate is null then 'RM' else 'DP' end from Account inner join acc_RupayAccount on Account.AccountId = acc_RupayAccount.RupayAccountId left join dbo.RupayUser on RupayUser.RupayUserId = acc_RupayAccount.RupayUserId left join dbo.legal_LegalEntity on legal_LegalEntity.RupayUserId = RupayUser.RupayUserId left join dbo.legal_Contract on legal_LegalEntity.ContractId = legal_Contract.ContractId left join dbo.legal_Bank on legal_Bank.BankId = legal_LegalEntity.BankId union all -- СКО select Account.AccountId ,Account.AmountCurrency ,Account.CreationDate ,'' as Name ,'' as FullName ,'' as Fax ,'' as Phone ,'' as SiteUrl ,'' as Inn ,'' as Kpp ,'' as LegalAddress ,'' as MobilePhone ,'' as Ogrn ,'' as Okpo ,'' as ContractId ,'' as ContractNumber ,'' as ContractDate ,'' as BankId ,'' AS SettleAccount ,'' AS NEWNUM ,'' as KSNP ,'' as LegalAddressYurik ,'' as RealAddressYurik ,'' as LegalEntityId ,'SKO' as fizik_goga , organization = case when Account.CompanyTransferDate is null then 'RM' else 'DP' end from Account inner join dbo.acc_InvoiceAccount on dbo.acc_InvoiceAccount.InvoiceAccountId = Account.AccountId Select RupayUser.RupayUserId, dbo.RupayUser.BirthDate From dbo.RupayUser inner join dbo.Account on dbo.Account.AccountId = RupayUser.RupayUserId ) as Tab
|
ругается матом, по раздельности всё работает ))
делал так:
| Код | Select top 1000 * from (select Account.AccountId ,Account.AmountCurrency ,Account.CreationDate ,legal_LegalEntity.Name ,legal_LegalEntity.FullName ,legal_LegalEntity.Fax ,legal_LegalEntity.Phone ,legal_LegalEntity.SiteUrl ,legal_LegalEntity.Inn ,legal_LegalEntity.Kpp ,legal_LegalEntity.LegalAddress ,legal_LegalEntity.MobilePhone ,legal_LegalEntity.Ogrn ,legal_LegalEntity.Okpo ,legal_Contract.ContractId ,legal_Contract.ContractNumber ,legal_Contract.ContractDate ,legal_LegalEntity.BankId ,legal_LegalEntity.SettleAccount ,legal_Bank.NEWNUM ,legal_Bank.KSNP ,legal_LegalEntity.LegalAddress as LegalAddressYurik ,legal_LegalEntity.RealAddress as RealAddressYurik ,legal_LegalEntity.LegalEntityId ,fizik_goga = case when legal_LegalEntity.LegalEntityId is not NULL then 'yurik' else 'fizik' end , organization = case when Account.CompanyTransferDate is null then 'RM' else 'DP' end from Account inner join acc_RupayAccount on Account.AccountId = acc_RupayAccount.RupayAccountId left join dbo.RupayUser on RupayUser.RupayUserId = acc_RupayAccount.RupayUserId left join dbo.legal_LegalEntity on legal_LegalEntity.RupayUserId = RupayUser.RupayUserId left join dbo.legal_Contract on legal_LegalEntity.ContractId = legal_Contract.ContractId left join dbo.legal_Bank on legal_Bank.BankId = legal_LegalEntity.BankId union all -- СКО select Account.AccountId ,Account.AmountCurrency ,Account.CreationDate ,'' as Name ,'' as FullName ,'' as Fax ,'' as Phone ,'' as SiteUrl ,'' as Inn ,'' as Kpp ,'' as LegalAddress ,'' as MobilePhone ,'' as Ogrn ,'' as Okpo ,'' as ContractId ,'' as ContractNumber ,'' as ContractDate ,'' as BankId ,'' AS SettleAccount ,'' AS NEWNUM ,'' as KSNP ,'' as LegalAddressYurik ,'' as RealAddressYurik ,'' as LegalEntityId ,'SKO' as fizik_goga , organization = case when Account.CompanyTransferDate is null then 'RM' else 'DP' end from Account inner join dbo.acc_InvoiceAccount on dbo.acc_InvoiceAccount.InvoiceAccountId = Account.AccountId Union All Select RupayUser.RupayUserId, RupayUser.BirthDate From dbo.RupayUser inner join dbo.Account on dbo.Account.AccountId = dbo.RupayUser.RupayUserId ) as Tab
|
и так тоже неправильно:
| Код | Select top 1000 * from (select Account.AccountId ,Account.AmountCurrency ,Account.CreationDate ,legal_LegalEntity.Name ,legal_LegalEntity.FullName ,legal_LegalEntity.Fax ,legal_LegalEntity.Phone ,legal_LegalEntity.SiteUrl ,legal_LegalEntity.Inn ,legal_LegalEntity.Kpp ,legal_LegalEntity.LegalAddress ,legal_LegalEntity.MobilePhone ,legal_LegalEntity.Ogrn ,legal_LegalEntity.Okpo ,legal_Contract.ContractId ,legal_Contract.ContractNumber ,legal_Contract.ContractDate ,legal_LegalEntity.BankId ,legal_LegalEntity.SettleAccount ,legal_Bank.NEWNUM ,legal_Bank.KSNP ,legal_LegalEntity.LegalAddress as LegalAddressYurik ,legal_LegalEntity.RealAddress as RealAddressYurik ,legal_LegalEntity.LegalEntityId ,fizik_goga = case when legal_LegalEntity.LegalEntityId is not NULL then 'yurik' else 'fizik' end , organization = case when Account.CompanyTransferDate is null then 'RM' else 'DP' end from Account inner join acc_RupayAccount on Account.AccountId = acc_RupayAccount.RupayAccountId left join dbo.RupayUser on RupayUser.RupayUserId = acc_RupayAccount.RupayUserId left join dbo.legal_LegalEntity on legal_LegalEntity.RupayUserId = RupayUser.RupayUserId left join dbo.legal_Contract on legal_LegalEntity.ContractId = legal_Contract.ContractId left join dbo.legal_Bank on legal_Bank.BankId = legal_LegalEntity.BankId union all -- СКО select Account.AccountId ,Account.AmountCurrency ,Account.CreationDate ,'' as Name ,'' as FullName ,'' as Fax ,'' as Phone ,'' as SiteUrl ,'' as Inn ,'' as Kpp ,'' as LegalAddress ,'' as MobilePhone ,'' as Ogrn ,'' as Okpo ,'' as ContractId ,'' as ContractNumber ,'' as ContractDate ,'' as BankId ,'' AS SettleAccount ,'' AS NEWNUM ,'' as KSNP ,'' as LegalAddressYurik ,'' as RealAddressYurik ,'' as LegalEntityId ,'SKO' as fizik_goga , organization = case when Account.CompanyTransferDate is null then 'RM' else 'DP' end from Account inner join dbo.acc_InvoiceAccount on dbo.acc_InvoiceAccount.InvoiceAccountId = Account.AccountId Union All Select RupayUser.RupayUserId, cast(RupayUser.BirthDate as date) , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL From dbo.RupayUser inner join dbo.Account on dbo.Account.AccountId = dbo.RupayUser.RupayUserId ) as Tab
|
помогите пожалуйста их объединить
|