• <legend id='Y5Lix'><style id='Y5Lix'><dir id='Y5Lix'><q id='Y5Lix'></q></dir></style></legend>
      <bdo id='Y5Lix'></bdo><ul id='Y5Lix'></ul>

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

      <tfoot id='Y5Lix'></tfoot>

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

      2. 如何在 SQL Server 上的 CASE WHEN 中选择多个列?

        How can I SELECT multiple columns within a CASE WHEN on SQL Server?(如何在 SQL Server 上的 CASE WHEN 中选择多个列?)
        <tfoot id='uTCF2'></tfoot>
            <tbody id='uTCF2'></tbody>
          • <bdo id='uTCF2'></bdo><ul id='uTCF2'></ul>

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

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

                  本文介绍了如何在 SQL Server 上的 CASE WHEN 中选择多个列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经广泛搜索了该网站,但找不到解决方案.

                  I have searched this site extensively but cannot find a solution.

                  这是我的查询示例:

                  SELECT 
                     ActivityID,
                  
                     Hours = (CASE 
                                  WHEN ActivityTypeID <> 2 THEN
                                       FieldName = (Some Aggregate Sub Query),
                                       FieldName2 = (Some other aggregate sub query)
                                  WHEN ActivityTypeID = 2 THEN
                                       FieldName = (Some Aggregate Sub Query with diff result),
                                       FieldName2 = (Some Other Aggregate Sub Query with diff result)
                             END)
                  

                  显然我遗漏了很多查询,我只是想看看是否有可能.

                  obviously I'm leaving out a lot of the query, I just wanted to see if it's possible.

                  我知道我可能只能做两次CASE",但我想我会问......

                  I know I probably could just do the "CASE" twice but figured I would ask...

                  推荐答案

                  问题在于 CASE 语句无法按照您尝试使用的方式工作.您只能使用它来切换查询中一个字段的值.如果我理解你想要做什么,你可能需要这个:

                  The problem is that the CASE statement won't work in the way you're trying to use it. You can only use it to switch the value of one field in a query. If I understand what you're trying to do, you might need this:

                  SELECT 
                     ActivityID,
                     FieldName = CASE 
                                    WHEN ActivityTypeID <> 2 THEN
                                        (Some Aggregate Sub Query)
                                    ELSE
                                       (Some Aggregate Sub Query with diff result)
                                 END,
                     FieldName2 = CASE
                                    WHEN ActivityTypeID <> 2 THEN
                                        (Some Aggregate Sub Query)
                                    ELSE
                                       (Some Aggregate Sub Query with diff result)
                                 END
                  

                  这篇关于如何在 SQL Server 上的 CASE WHEN 中选择多个列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                  • <legend id='aUCtl'><style id='aUCtl'><dir id='aUCtl'><q id='aUCtl'></q></dir></style></legend>
                      <bdo id='aUCtl'></bdo><ul id='aUCtl'></ul>
                            <tfoot id='aUCtl'></tfoot>
                          1. <small id='aUCtl'></small><noframes id='aUCtl'>

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

                              <tbody id='aUCtl'></tbody>