<i id='C8h4q'><tr id='C8h4q'><dt id='C8h4q'><q id='C8h4q'><span id='C8h4q'><b id='C8h4q'><form id='C8h4q'><ins id='C8h4q'></ins><ul id='C8h4q'></ul><sub id='C8h4q'></sub></form><legend id='C8h4q'></legend><bdo id='C8h4q'><pre id='C8h4q'><center id='C8h4q'></center></pre></bdo></b><th id='C8h4q'></th></span></q></dt></tr></i><div id='C8h4q'><tfoot id='C8h4q'></tfoot><dl id='C8h4q'><fieldset id='C8h4q'></fieldset></dl></div>
    <tfoot id='C8h4q'></tfoot>
    <legend id='C8h4q'><style id='C8h4q'><dir id='C8h4q'><q id='C8h4q'></q></dir></style></legend>
      <bdo id='C8h4q'></bdo><ul id='C8h4q'></ul>

      <small id='C8h4q'></small><noframes id='C8h4q'>

        GROUP BY 子句中不允许使用 Sql 服务器 XML 方法

        时间:2023-06-07

              <legend id='70Ght'><style id='70Ght'><dir id='70Ght'><q id='70Ght'></q></dir></style></legend>
              <i id='70Ght'><tr id='70Ght'><dt id='70Ght'><q id='70Ght'><span id='70Ght'><b id='70Ght'><form id='70Ght'><ins id='70Ght'></ins><ul id='70Ght'></ul><sub id='70Ght'></sub></form><legend id='70Ght'></legend><bdo id='70Ght'><pre id='70Ght'><center id='70Ght'></center></pre></bdo></b><th id='70Ght'></th></span></q></dt></tr></i><div id='70Ght'><tfoot id='70Ght'></tfoot><dl id='70Ght'><fieldset id='70Ght'></fieldset></dl></div>

                <bdo id='70Ght'></bdo><ul id='70Ght'></ul>

                <tfoot id='70Ght'></tfoot>

                • <small id='70Ght'></small><noframes id='70Ght'>

                    <tbody id='70Ght'></tbody>
                  本文介绍了GROUP BY 子句中不允许使用 Sql 服务器 XML 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我只是通过在其中指定 xml 数据的位置发出一个组,然后出现错误 在 GROUP BY 子句中不允许使用 XML 方法.

                  i just issue a group by where i specify xml data then i got error XML methods are not allowed in a GROUP BY clause.

                  这是我的 sql

                  SELECT HourSheetID,(MAX(RowID)+1) as "RowID",
                  XMLData.value('(Log/EntryDate)[1]','datetime') as EntryDate,
                  XMLData.value('(Log/SpecialistID)[1]','int') as SpecialistID,
                  XMLData.value('(Log/HoursData)[1]','decimal(18,2)') as HoursData,
                  XMLData.value('(Log/UpdatedBy)[1]','varchar(max)') as UpdatedBy,
                  XMLData.value('(Log/Options)[1]','varchar(max)') as Options,
                  logdate
                  FROM  dbo.EditedHourSheetLog
                  GROUP BY HourSheetID,
                  XMLData.value('(Log/EntryDate)[1]','datetime'),
                  XMLData.value('(Log/SpecialistID)[1]','int'),
                  XMLData.value('(Log/HoursData)[1]','decimal(18,2)'),
                  XMLData.value('(Log/UpdatedBy)[1]','varchar(max)'),
                  XMLData.value('(Log/Options)[1]','varchar(max)'),
                  logdate
                  

                  如果我不能按条款指定组中的 xml 数据,那么还有什么其他选项可用....请指导.谢谢

                  if i can not specify xml data in group by cluase then what other option is available....please guide. thanks

                  ALTER PROC sp_HourSheetLog
                  (
                      @StartDate VARCHAR(8),
                      @EndDate VARCHAR(8)
                  )
                  AS
                  
                  SELECT B.ID
                      ,A.RowID
                      ,B.EntryDate
                      ,B.Name
                      ,B.HoursData
                      ,B.UpdatedBy
                      ,Options=(CASE B.Options
                      WHEN 'rdLeave' THEN 'Leave'
                      WHEN 'rdsick' THEN 'Sick'
                      WHEN 'rdSalvage' THEN 'Salvage'
                      WHEN 'rdCSRDuty' THEN 'CSR Duty'
                      WHEN 'rdShippingSales' THEN 'Shipping and Sales'
                      WHEN 'rdEOL' THEN 'EOL'
                      WHEN 'rdTraining' THEN 'Training'
                      WHEN 'rdOther' THEN 'Other'
                      END)
                      ,B.ModDate
                          FROM (
                          (
                              SELECT HourSheetID,(MAX(RowID)+1) as "RowID"
                              FROM EditedHourSheetLog l,EditedHourSheet h
                              GROUP BY HourSheetID
                          ) A
                          JOIN
                          (
                              SELECT h.ID
                                  ,s.Name
                                  ,h.EntryDate
                                  ,h.HoursData
                                  ,h.Options 
                                  ,h.UpdatedBy
                                  ,h.ModDate from EditedHourSheet h
                                  LEFT JOIN Specialists s
                                  ON h.SpecialistID=s.SpecialistID
                          ) B
                      ON A.HourSheetID=B.ID
                      )
                      WHERE Convert(Varchar,ModDate,112)>=@StartDate AND
                      Convert(Varchar,ModDate,112)<=@EndDate
                  
                  
                  UNION 
                  (
                      Select HourSheetID as ID,RowID,
                      XMLData.value('(Log/EntryDate)[1]','datetime') as EntryDate,
                      --XMLData.value('(Log/SpecialistID)[1]','int') as SpecialistID,
                      s.Name,
                      XMLData.value('(Log/HoursData)[1]','decimal(18,2)') as HoursData,
                      CAST(XMLData.value('(Log/UpdatedBy)[1]','varchar(max)') AS VARCHAR(MAX)) UpdatedBy,
                      Options=(CASE XMLData.value('(Log/Options)[1]','varchar(max)')
                      WHEN 'rdLeave' THEN 'Leave'
                      WHEN 'rdsick' THEN 'Sick'
                      WHEN 'rdSalvage' THEN 'Salvage'
                      WHEN 'rdCSRDuty' THEN 'CSR Duty'
                      WHEN 'rdShippingSales' THEN 'Shipping and Sales'
                      WHEN 'rdEOL' THEN 'EOL'
                      WHEN 'rdTraining' THEN 'Training'
                      WHEN 'rdOther' THEN 'Other'
                      END),
                      LogDate as ModDate
                      FROM EditedHourSheetLog h
                      LEFT JOIN Specialists s
                      ON h.XMLData.value('(Log/SpecialistID)[1]','int')=s.SpecialistID
                      WHERE Convert(Varchar,LogDate,112)>=@StartDate AND
                      Convert(Varchar,LogDate,112)<=@EndDate
                  
                  )
                  ORDER BY ID,RowID DESC
                  
                  --sp_HourSheetLog '20140101','20140326'
                  

                  推荐答案

                  您可以使用派生表并在主查询中进行分组.

                  You can use a derived table and do the group by in the main query.

                  SELECT T.HourSheetID,
                         MAX(T.RowID)+1 as RowID,
                         T.EntryDate,
                         T.SpecialistID,
                         T.HoursData,
                         T.UpdatedBy,
                         T.Options,
                         T.logdate
                  FROM (
                       SELECT HourSheetID,
                              RowID,
                              XMLData.value('(Log/EntryDate)[1]','datetime') as EntryDate,
                              XMLData.value('(Log/SpecialistID)[1]','int') as SpecialistID,
                              XMLData.value('(Log/HoursData)[1]','decimal(18,2)') as HoursData,
                              XMLData.value('(Log/UpdatedBy)[1]','varchar(max)') as UpdatedBy,
                              XMLData.value('(Log/Options)[1]','varchar(max)') as Options,
                              logdate
                       FROM  dbo.EditedHourSheetLog
                       ) AS T
                  GROUP BY T.HourSheetID,
                           T.EntryDate,
                           T.SpecialistID,
                           T.HoursData,
                           T.UpdatedBy,
                           T.Options,
                           T.logdate
                  

                  这篇关于GROUP BY 子句中不允许使用 Sql 服务器 XML 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:查询具有 xmlns 节点属性的 XML 数据类型 下一篇:以递归方式将 xml 粉碎到数据库中

                  相关文章

                  最新文章

                    <i id='6pNrD'><tr id='6pNrD'><dt id='6pNrD'><q id='6pNrD'><span id='6pNrD'><b id='6pNrD'><form id='6pNrD'><ins id='6pNrD'></ins><ul id='6pNrD'></ul><sub id='6pNrD'></sub></form><legend id='6pNrD'></legend><bdo id='6pNrD'><pre id='6pNrD'><center id='6pNrD'></center></pre></bdo></b><th id='6pNrD'></th></span></q></dt></tr></i><div id='6pNrD'><tfoot id='6pNrD'></tfoot><dl id='6pNrD'><fieldset id='6pNrD'></fieldset></dl></div>
                  1. <tfoot id='6pNrD'></tfoot>

                    <small id='6pNrD'></small><noframes id='6pNrD'>

                      <bdo id='6pNrD'></bdo><ul id='6pNrD'></ul>

                    <legend id='6pNrD'><style id='6pNrD'><dir id='6pNrD'><q id='6pNrD'></q></dir></style></legend>