我有两个查询(由一些临时表组成),我想要联合在一起.当我用联盟注释掉一个(无关紧要的)查询时,它可以工作.但是当我介绍union时,我得到ntext数据类型不能被选为DISTINCT,因为它不具有可比性.
我不明白为什么,因为这两个主要查询都不使用.主要选择参考:
我不明白为什么,因为这两个主要查询都不使用.主要选择参考:
SELECT dbo.CUSTTABLE.ACCOUNTNUM AS 'Account Number',dbo.CUSTTABLE.NAME AS 'Customer Name',[DESCRIPTION] AS 'Division',ISNULL(dbo.USERINFO.NAME,'OPEN') AS 'Sales Engineer',[STATE],PHONE,PAYMTERMID AS 'Terms',(CASE BLOCKED WHEN 0 THEN 'No' WHEN 2 THEN 'Financial Hold' WHEN 1 THEN 'System Hold' ELSE 'Unknown' END) AS 'Status',[45-60],[61-90],[91-120],[120+],#temptable2.Today,ISNULL(USERMEMO,'') AS 'Notes',ISNULL(#temptable2.Today / NULLIF((ISNULL(#salesTemp.PQ1,0) / 90),0),0) AS 'DSO1',CustTable.StatisticsGroup as 'Past Due Category' FROM dbo.CUSTTABLE INNER JOIN dbo.DIMENSIONS ON DIMENSION2_ = NUM INNER JOIN #temptable2 ON dbo.CUSTTABLE.ACCOUNTNUM = #temptable2.ACCOUNTNUM LEFT OUTER JOIN #temptable ON dbo.CUSTTABLE.ACCOUNTNUM = #temptable.ACCOUNTNUM LEFT OUTER JOIN dbo.SMMSALESUNITMEMBERS ON SALESGROUP = SALESUNITID AND SALESMANAGER = 1 LEFT OUTER JOIN dbo.USERINFO ON ID = SALESMANID AND [ENABLE] = 1 JOIN #salesTemp on #salesTemp.ACCOUNTNUM = CUSTTABLE.ACCOUNTNUM WHERE DIMENSION2_ IN (@division) UNION SELECT Customer_ID AS 'Account Number',Customer_Name AS 'Customer Name','South Bend' AS Division,'' AS 'Sales Engineer','Indiana' AS 'State','' AS 'Phone',Customer_Terms AS 'Terms','' AS 'Status',[Today],'' AS 'Notes','' AS 'DSO1','' AS 'Past Due Category' FROM #temptable4