-2

如何将以下查询合并为一个。

SELECT MID,
       Status,
       Owner1Fname,
       Owner1Lname,
       LegalName,
       DBAName,
       DBAEmail,
       DBAPhone,
       CorpPhone,
       SICCode
FROM   vw_merLeadData

SELECT replastname,
       replastname
FROM   vw_XXX_Page1

SELECT installdate,
       model,
       ownership,
       serialno
FROM   dbo.merequip 
4

1 回答 1

1

像以前的评论者一样,我不确定您为什么要这样做,但是我不知道您有什么需要它的背景,所以我想您有充分的理由!无论如何,这就是您的做法(抱歉无用的格式):

SELECT MID,
   Status,
   Owner1Fname,
   Owner1Lname,
   LegalName,
   DBAName,
   DBAEmail,
   DBAPhone,
   CorpPhone,
   SICCode,
   replastname=NULL,
   replastname=NULL,
   installdate=NULL,
   model=NULL,
   ownership=NULL,
   serialno=NULL
   FROM   vw_merLeadData
   UNION ALL
   SELECT MID=NULL,
   Status=NULL,
   Owner1Fname=NULL,
   Owner1Lname=NULL,
   LegalName=NULL,
   DBAName=NULL,
   DBAEmail=NULL,
   DBAPhone=NULL,
   CorpPhone=NULL,
   SICCode=NULL,
   replastname=NULL,
   replastname=NULL,
   installdate=NULL,
   model=NULL,
   ownership=NULL,
   serialno=NULL       
FROM   vw_XXX_Page1
UNION ALL
SELECT 
MID=NULL,
   Status=NULL,
   Owner1Fname=NULL,
   Owner1Lname=NULL,
   LegalName=NULL,
   DBAName=NULL,
   DBAEmail=NULL,
   DBAPhone=NULL,
   CorpPhone=NULL,
   SICCode=NULL,
replastname=NULL,
   replastname=NULL,
installdate,
   model,
   ownership,
   serialno
 FROM   dbo.merequip 

基本上,您可以将任何 tqo 查询合并在一起,只要它们具有相同数量的列并且每个字段中的数据类型与其他查询中的相应字段相同(或至少可转换),因此所有 NULL 都只是虚拟列。
希望有帮助。

于 2013-01-16T23:40:41.300 回答