SELECT DISTINCT order by 同样的语句同样环境报错?特急!

qq_27341511 2017-03-09 02:30:20
报错提示:
如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。

但很奇怪,同样的语句在同样的数据库结构里,一个执行报错,一个执行不报错!
找不到原因,难道和数据库的属性有关系吗?

大神来分析一下!! 谢谢!
...全文
480 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_27341511 2017-03-12
  • 打赏
  • 举报
回复
果然是兼容性设置问题, 设置成2008(100)就通不过,设置成2000(80)就能通过! 谢谢!!
Tiger_Zhao 2017-03-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 qq_27341511 的回复:]请教兼容级别属性在哪查? [/Quote]
数据库右键\属性\选项\兼容级别
道素 2017-03-09
  • 打赏
  • 举报
回复
distinct 某种层度就是聚合,比如比较下面两个语句

SELECT DISTINCT type FROM master.dbo.spt_values
SELECT type FROM master.dbo.spt_values GROUP BY type


tcmakebest 2017-03-09
  • 打赏
  • 举报
回复
如果使用了distinct ,那排序的字段理应在结果列中, 不然如何排序呢.
qq_27341511 2017-03-09
  • 打赏
  • 举报
回复
请教兼容级别属性在哪查?
Tiger_Zhao 2017-03-09
  • 打赏
  • 举报
回复
可以看看数据库属性中的兼容级别是否一致。
换成下面这样可以不?
ORDER BY ia_subsidiary.cvoutype,
dkeepdate,
ia_subsidiary.cvoucode,
cwhcode
qq_27341511 2017-03-09
  • 打赏
  • 举报
回复
同一个数据库下面的两个完全相同的数据实例,一个是2016年的,一个是2017年的。 不管数据怎样,一个报错一个不报错,找原因都没有方向! 各个表结构方面都是一样的,但脚本的语法是否错误应该和数据内容无关吧? 语句如下: SELECT Distinct convert(nvarchar(10),IA_Subsidiary.dKeepDate,21) as dKeepDate, convert(nvarchar(10),IA_Subsidiary.dVouDate,21) as dVouDate,enum1.enumname AS cVouchName,IA_Subsidiary.cVouCode, case when cvoutype= N'22' then N'' else (case when (0=1 and cvoutype= N'35') then N'' else cWhName end) end as cWhName, case when cvoutype= N'35' then N'' else Rd_Style.cRdName end as cRdName,IA_Subsidiary.cAccounter, IA_Subsidiary.cVouType, case when cvoutype= N'22' then N'' else (case when (0=1 and cvoutype= N'35') then N'' else IA_Subsidiary.cWhCode end) end as cWhcode, case when cvoutype= N'35' then N'' else Rd_Style.cRdCode end as cRdCode,case when cvoutype= N'35' then N'' else cDepName end as cAccDepName, case when cvoutype= N'35' then N'' else cAccDep end as cAccDepCode,case when cvoutype= N'22' then N'' else IA_Subsidiary.cDepCode end as cDepCode, case when (left(IsNull(IA_Subsidiary.cBusType, N''),2)= N'调拨' or left(IsNull(IA_Subsidiary.cBusType, N''),2)= N'组装' or left(IsNull(IA_Subsidiary.cBusType, N''),2)= N'拆卸' or left(IsNull(IA_Subsidiary.cBusType, N''),2)= N'转换') then IA_Subsidiary.cBusCode else N'' end As cBusCode, CASE WHEN (cVouType= N'24' or cVouType= N'30') then IA_Subsidiary.AutoID else ipzid end as MainID, IA_Subsidiary.id as id, enum2.enumname as cBusTypeDis,IA_Subsidiary.cSrcVouType,enum3.enumname as cWhValueStyleDis, 'Sub' As cSource, IA_Subsidiary.AutoID, IA_Subsidiary.ID, IsNull(IA_Subsidiary.cBusType, N'') As cBusType,IA_Subsidiary.psvsid as psvsid FROM (Warehouse RIGHT JOIN (department RIGHT JOIN (Rd_Style RIGHT JOIN (VouchType RIGHT JOIN IA_Subsidiary ON VouchType.cVouchType = IA_Subsidiary.cVouType) ON Rd_Style.cRdCode = IA_Subsidiary.cRdCode) ON department.cDepCode = IA_Subsidiary.cAccDep) ON Warehouse.cWhCode = IA_Subsidiary.cWhCode) Left join inventory on ia_subsidiary.cinvcode=inventory.cinvcode left join aa_enum enum1 on enum1.enumtype= N'IA.VchType' and enum1.enumcode=(case when CVOUTYPE= N'2501' then N'直运采购发票'else (CASE WHEN CVOUTYPE= N'35' THEN N'差异结转单' ELSE case when (IsNull(IA_Subsidiary.cBusType, N'')= N'假退料' and cvoutype= N'11') then N'假退料单' else VouchType.cVouchName end END) end ) and enum1.localeid= dbo.UDF_GetLocaleID() left join aa_enum enum2 on enum2.enumtype= N'IA.Bustype' and enum2.enumcode=IsNull(IA_Subsidiary.cBusType, N'') and enum2.localeid= dbo.UDF_GetLocaleID() left join aa_enum enum3 on enum3.enumtype= N'IA.ValueStyle' and enum3.enumcode=(case when cvoutype= N'22' then N'' else (case when (0=1 and cvoutype= N'35') then N'' else cWhValueStyle end) end ) and enum3.localeid= dbo.UDF_GetLocaleID() left join Rdrecords RdsCheck on RdsCheck.bCosting = 1 And RdsCheck.ID = IA_Subsidiary.iPZID And IsNull(RdsCheck.cBAccounter, N'') = N'' and Not Left(IA_Subsidiary.cVouType, 2) In (N'70', N'ex', N'05', N'06', N'5', N'6', N'25', N'26', N'27', N'28', N'29', N'20', N'21', N'22', N'35', N'24', N'30') left join PU_T_VMIUsedVouchs VmiCheck on VmiCheck.bCosting = 1 And VmiCheck.ID = IA_Subsidiary.iPZID And IsNull(VmiCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) In (N'70') left join DispatchLists DisCheck on DisCheck.bCosting = 1 And DisCheck.DLID = IA_Subsidiary.iPZID And IsNull(DisCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) In (N'05', N'06', N'5', N'6') left join SalebillVouchs BillCheck on BillCheck.bCosting = 1 And BillCheck.SBVID = IA_Subsidiary.iPZID And IsNull(BillCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) In (N'26', N'27', N'28', N'29') left join purbillvouchs pusCheck on pusCheck.bCosting = 1 And pusCheck.PBVID = IA_Subsidiary.iPZID And IsNull(pusCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) = N'25' left join JustInVouchs JustCheck on JustCheck.bCosting = 1 And JustCheck.cJVCode = IA_Subsidiary.cVouCode And IsNull(JustCheck.cBAccounter, N'') = N'' and IA_Subsidiary.cVouType In (N'20', N'21') left join ex_invoicedetail EXsCheck on EXsCheck.bCosting = 1 And EXsCheck.ID = IA_Subsidiary.iPZID And IsNull(EXsCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) = N'ex' where IA_subsidiary.cVouType<> N'33' and IA_subsidiary.cVouType<> N'34' and ((imonth<>0 and substring(IsNull(IA_Subsidiary.cBusType, N''),1,2) = N'直运') or substring(IsNull(IA_Subsidiary.cBusType, N''),1,2) <> N'直运' or IA_subsidiary.cbustype is null) and cpzid is null And RdsCheck.ID Is Null And VmiCheck.ID Is Null And DisCheck.DLID Is Null And BillCheck.SBVID Is Null And pusCheck.ID Is Null And JustCheck.cJVCode Is Null And EXsCheck.ID Is Null AND IA_Subsidiary.cVouCode>= N'123456' AND ((Ia_Subsidiary.cVouType= N'01' and bFlag=1) or (Ia_Subsidiary.cVouType= N'01' and bFlag<>1) or (Ia_Subsidiary.cVouType= N'70' and bFlag=1) or (Ia_Subsidiary.cVouType= N'70' and bFlag<>1) or (Ia_Subsidiary.cVouType= N'10') or (Ia_Subsidiary.cVouType= N'08') or (Ia_Subsidiary.cVouType= N'26' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'27' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'28' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'29' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'32' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'11' and Ia_Subsidiary.cBusType<> N'假退料' ) or (Ia_Subsidiary.cVouType= N'09' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'20' and (isnull(iAInPrice,0)<>0 or isnull(iDebitDifCost,0)<>0 or isnull(iCreditDifCost,0)<>0)) or (Ia_Subsidiary.cVouType= N'21') or (Ia_Subsidiary.cVouType= N'22') or (Ia_Subsidiary.cVouType= N'35') or (Ia_Subsidiary.cVouType= N'24') or (Ia_Subsidiary.cVouType= N'30' and bFlag=1) or (Ia_Subsidiary.cVouType= N'30' and bFlag<>1) or (Ia_Subsidiary.cVouType= N'05' and Ia_Subsidiary.cBusType= N'分期收款' and imonth <> 0) or (Ia_Subsidiary.cVouType= N'05') or (Ia_Subsidiary.cVouType= N'06') or (Ia_Subsidiary.cVouType= N'AA') or (Ia_Subsidiary.cVouType= N'AA') or (Ia_Subsidiary.cVouType= N'27' and not iOutCost is null and imonth <> 0 and not Ia_Subsidiary.cBusType in (N'分期收款',N'委托',N'直运销售') ) or (Ia_Subsidiary.cVouType= N'27' and not iOutCost is null and imonth <> 0 and not Ia_Subsidiary.cBusType in (N'分期收款',N'委托',N'直运销售') ) or (Ia_Subsidiary.cVouType= N'66') or (Ia_Subsidiary.cVouType= N'66') or (Ia_Subsidiary.cVouType Like N'25%' and Ia_Subsidiary.cBusType= N'直运采购' and imonth <> 0) or (Ia_Subsidiary.cVouType= N'25') or (Ia_Subsidiary.cVouType in ( N'26',N'27') and Ia_Subsidiary.cBusType= N'直运销售' and imonth <> 0 ) or (Ia_Subsidiary.cVouType In ( N'EX26',N'EX27') and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType in ( N'EX26',N'EX27') and Ia_Subsidiary.cBusType= N'直运销售' and imonth <> 0 ) or (Ia_Subsidiary.cVouType= N'11' and Ia_Subsidiary.cBusType= N'假退料' ) or (Ia_Subsidiary.cVouType= N'61')) and ( ((Not warehouse.cwhcode IN (Select cWhCode From Warehouse Where bInCost = 0)) or warehouse.cwhcode is null) Or warehouse.cwhcode Is Null) Order by IA_Subsidiary.cVouType,IA_Subsidiary.dKeepDate,IA_subsidiary.cVoucode,IA_Subsidiary.cWhCode
二月十六 2017-03-09
  • 打赏
  • 举报
回复
不能够,贴上来一下数据结构和你的语句让大家看看
卖水果的net 2017-03-09
  • 打赏
  • 举报
回复
不会的,分别说一下两个库的版本。
在Windows 10或Windows 11操作系统中,用户经常会遇到共享打印机时出现的一系列错误代码,这些错误代码可能会阻碍打印机共享功能的正常使用。常见的错误代码包括0x00000057、0x00000709和0x0000011b,这些代码通常指出了不同的问题,比如权限不足、服务未运行或配置错误等。除此之外,还有一些故障提示如“连接失败”或“内存不足”,这些都可能影响到打印机共享的稳定性。 要解决这些故障,首先要确保打印机已经正确地连接到网络,并且在需要共享的电脑上进行了设置。确保打印机驱动程序是最新的,并且在共享设置中没有错误配置。对于权限问题,需要检查网络上的用户账户是否具有足够的权限来访问共享打印机。同时,也要确保打印机服务正在运行,特别是“Print Spooler”服务,因为这是打印机共享服务的核心组件。 在某些情况下,问题可能与操作系统的更新有关,如升级到最新版的Windows 10或Windows 11后可能出现的兼容性问题。这时,可能需要查看微软的官方支持文档来获取特定的解决方案或更新。 对于错误代码0x00000057,这通常是由于没有足够的权限来访问网络打印机或其共享资源,解决方法是确保网络打印机的权限设置正确,包括在组策略中设置相应的访问权限。而0x00000709错误可能是由于打印机驱动问题或打印机端口配置错误,可以尝试重新安装或更新打印机驱动来解决。至于0x0000011b错误,这往往是因为打印机队列服务的问题,检查并重启“Print Spooler”服务通常是解决这类问题的常见手段。 至于“连接失败”或“内存不足”这类故障,通常与客户端和打印机之间的网络连接以及打印机本地资源的使用情况有关。检查网络连接,确保打印机所在的网络段没有故障或中断。同时,如果打印机的打印队列长时间得不到处理,可能会导致内存不足的情况,这时可能需要清理打印队列或增加打印机的内存配置。 为了帮助用户更快速地解决这些问题,市面上出现了各种打印机共享错误修复工具。这些工具往往通过预设的修复程序来自动检测和修正打印机共享中常见的问题。它们可以快速检查打印机驱动、网络连接以及共享设置,并且能够提供一键修复功能,大幅减少了用户自行排查和解决问题的难度。 然而,在使用这些修复工具之前,用户应确保这些工具的来源是安全可靠的,避免因使用不当的修复工具而引发其他系统安全或隐私问题。用户可以到官方平台或者信誉良好的软件提供商处下载这些工具。通过细心检查打印机的共享设置,及时更新驱动程序和服务,以及合理使用修复工具,大多数共享打印机的问题都可以得到有效的解决。

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧