pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

    1. <small id='YXaAA'></small><noframes id='YXaAA'>

    2. <tfoot id='YXaAA'></tfoot>

      1. 嵌套計算列“無效的列名"錯誤(T-SQL 列別名

        Nested computed column quot;Invalid column namequot; error (T-SQL Column alias)(嵌套計算列“無效的列名錯誤(T-SQL 列別名))
      2. <tfoot id='dv5P9'></tfoot>
        • <i id='dv5P9'><tr id='dv5P9'><dt id='dv5P9'><q id='dv5P9'><span id='dv5P9'><b id='dv5P9'><form id='dv5P9'><ins id='dv5P9'></ins><ul id='dv5P9'></ul><sub id='dv5P9'></sub></form><legend id='dv5P9'></legend><bdo id='dv5P9'><pre id='dv5P9'><center id='dv5P9'></center></pre></bdo></b><th id='dv5P9'></th></span></q></dt></tr></i><div class="ucismvb" id='dv5P9'><tfoot id='dv5P9'></tfoot><dl id='dv5P9'><fieldset id='dv5P9'></fieldset></dl></div>

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

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

                  本文介紹了嵌套計算列“無效的列名"錯誤(T-SQL 列別名)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我創建了 3 個計算列作為別名,然后使用別名列來計算總成本.這是查詢:

                  I've create 3 computed columns as alias and then used the aliased columns to calculate the total cost. This is the query:

                  SELECT TOP 1000 [Id]
                        ,[QuantityOfProduct]
                        ,[Redundant_ProductName]
                        ,[Order_Id]
                        ,(CASE 
                              WHEN [PriceForUnitOverride] is NULL 
                                  THEN [Redundant_PriceForUnit]
                              ELSE
                                  [PriceForUnitOverride]
                          END
                          ) AS [FinalPriceForUnit]
                  
                        ,(CASE 
                              WHEN [QuantityUnit_Override] is NULL 
                                  THEN [Redundant_QuantityUnit]
                              ELSE
                                  [QuantityUnit_Override]
                          END
                          ) AS [FinalQuantityUnit]
                  
                        ,(CASE 
                              WHEN [QuantityAtomic_Override] is NULL 
                                  THEN [Redundant_QuantityAtomic]
                              ELSE
                                  [QuantityAtomic_Override]
                          END
                          ) AS [Final_QuantityAtomic]
                  
                           --***THIS IS WHERE THE QUERY CREATES AN ERROR***--
                          ,([QuantityOfProduct]*[FinalPriceForUnit]*
                    ([Final_QuantityAtomic]/[FinalQuantityUnit])) AS [Final_TotalPrice]
                  
                  
                    FROM [dbo].[ItemInOrder]
                  
                    WHERE [IsSoftDeleted] = 0
                    ORDER BY [Order_Id] 
                  

                  控制臺返回此錯誤消息:

                  The console returns this ERROR message:

                  Msg 207, Level 16, State 1, Line 55
                  Invalid column name 'FinalPriceForUnit'.
                  Msg 207, Level 16, State 1, Line 55
                  Invalid column name 'Final_QuantityAtomic'.
                  Msg 207, Level 16, State 1, Line 55
                  Invalid column name 'FinalQuantityUnit'.
                  

                  如果我刪除AS [Final_TotalPrice]"別名計算列,則不會發生錯誤,但我需要總價.我該如何解決這個問題?似乎在達到 Final_TotalPrice 時還沒有創建其他別名.

                  If I remove the "AS [Final_TotalPrice]" alias computed column, no error occurs, but I need the total price. How can I solve this issue? It seems as the other aliases have not been created when the Final_TotalPrice is reached.

                  推薦答案

                  不能在同一個選擇中使用表別名.正常的解決方案是 CTE 或子查詢.但是,SQL Server 也提供 APPLY.(Oracle 還支持 APPLY,其他數據庫(例如 Postgres)支持使用 LATERAL 關鍵字進行橫向連接.)

                  You can't use table aliases in the same select. The normal solution is CTEs or subqueries. But, SQL Server also offers APPLY. (Oracle also supports APPLY and other databases such as Postgres support lateral joins using the LATERAL keyword.)

                  我喜歡這個解決方案,因為你可以創建任意嵌套的表達式而不必擔心縮進:

                  I like this solution, because you can create arbitrarily nested expressions and don't have to worry about indenting:

                  SELECT TOP 1000 io.Id, io.QuantityOfProduct, io.Redundant_ProductName,
                         io.Order_Id,
                         x.FinalPriceForUnit, x.FinalQuantityUnit, x.Final_QuantityAtomic,
                         (x.QuantityOfProduct * x.FinalPriceForUnit * x.Final_QuantityAtomic / x.FinalQuantityUnit
                         ) as Final_TotalPrice
                  FROM dbo.ItemInOrder io OUTER APPLY
                       (SELECT COALESCE(PriceForUnitOverride, Redundant_PriceForUnit) as FinalPriceForUnit,
                               COALESCE(QuantityUnit_Override, Redundant_QuantityUnit) as FinalQuantityUnit
                               COALESCE(QuantityAtomic_Override, Redundant_QuantityAtomic) as Final_QuantityAtomic
                       ) x
                  WHERE io.IsSoftDeleted = 0
                  ORDER BY io.Order_Id ;
                  

                  注意事項:

                  • 我發現 [] 根本無法幫助我閱讀或編寫查詢.
                  • COALESCE() 比您的 CASE 語句簡單得多.
                  • 使用 COALESCE(),您可能會考慮只將 COALESCE() 表達式放入最終計算中.
                  • I don't find that [ and ] help me read or write queries at all.
                  • COALESCE() is much simpler than your CASE statements.
                  • With COALESCE() you might consider just putting the COALESCE() expression in the final calculation.

                  這篇關于嵌套計算列“無效的列名"錯誤(T-SQL 列別名)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數據庫列表和 SQL Server 實例使用的空間嗎?) - IT屋-程序員軟件開發
                  How to create a login to a SQL Server instance?(如何創建對 SQL Server 實例的登錄?)
                  How to know the version and edition of SQL Server through registry search(如何通過注冊表搜索知道SQL Server的版本和版本)
                  Why do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(為什么會出現“數據類型轉換錯誤?使用 ExecuteNonQuery()?)
                  How to show an image from a DataGridView to a PictureBox?(如何將 DataGridView 中的圖像顯示到 PictureBox?)
                  WinForms application design - moving documents from SQL Server to file storage(WinForms 應用程序設計——將文檔從 SQL Server 移動到文件存儲)

                  <small id='3Vzuf'></small><noframes id='3Vzuf'>

                      <tfoot id='3Vzuf'></tfoot>
                        <bdo id='3Vzuf'></bdo><ul id='3Vzuf'></ul>

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

                              <tbody id='3Vzuf'></tbody>
                            <legend id='3Vzuf'><style id='3Vzuf'><dir id='3Vzuf'><q id='3Vzuf'></q></dir></style></legend>
                            主站蜘蛛池模板: 水性绝缘漆_凡立水_绝缘漆树脂_环保绝缘漆-深圳维特利环保材料有限公司 | 高压包-点火器-高压发生器-点火变压器-江苏天网| 钛合金标准件-钛合金螺丝-钛管件-钛合金棒-钛合金板-钛合金锻件-宝鸡远航钛业有限公司 | 螺杆真空泵_耐腐蚀螺杆真空泵_水环真空泵_真空机组_烟台真空泵-烟台斯凯威真空 | 课件导航网_ppt课件_课件模板_课件下载_最新课件资源分享发布平台 | 工业洗衣机_工业洗涤设备_上海力净工业洗衣机厂家-洗涤设备首页 bkzzy在职研究生网 - 在职研究生招生信息咨询平台 | 电池挤压试验机-自行车喷淋-车辆碾压试验装置-深圳德迈盛测控设备有限公司 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 超声波清洗机_大型超声波清洗机_工业超声波清洗设备-洁盟清洗设备 | 石家庄救护车出租_重症转院_跨省跨境医疗转送_活动赛事医疗保障_康复出院_放弃治疗_腾康26年医疗护送转诊团队 | 山楂片_雪花_迷你山楂片_山楂条饼厂家-青州市丰源食品厂 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 天津中都白癜风医院_天津白癜风医院_天津治疗白癜风 | 闪电优家-卫生间防水补漏_酒店漏水渗水维修_防水堵漏公司 | 济南拼接屏_山东液晶拼接屏_济南LED显示屏—维康国际官网 | 蓄电池在线监测系统|SF6在线监控泄露报警系统-武汉中电通电力设备有限公司 | 亮化工程,亮化设计,城市亮化工程,亮化资质合作,长沙亮化照明,杰奥思【官网】 | 软文发布-新闻发布推广平台-代写文章-网络广告营销-自助发稿公司媒介星 | 保健品OEM贴牌代加工厂家_德州健之源| 机制砂选粉机_砂石选粉机厂家-盐城市助成粉磨科技有限公司 | 能耗监测系统-节能监测系统-能源管理系统-三水智能化 | 无纺布包装机|径向缠绕包装机|缠绕膜打包机-上海晏陵智能设备有限公司 | 数控车床-立式加工中心-多功能机床-小型车床-山东临沂金星机床有限公司 | 广东西屋电气有限公司-广东西屋电气有限公司 | 震动筛选机|震动分筛机|筛粉机|振筛机|振荡筛-振动筛分设备专业生产厂家高服机械 | 路斯特伺服驱动器维修,伦茨伺服驱动器维修|万骏自动化百科 | 防爆型气象站_农业气象站_校园气象站_农业四情监测系统「山东万象环境科技有限公司」 | 风电变桨伺服驱动器-风电偏航变桨系统-深圳众城卓越科技有限公司 | 芜湖厨房设备_芜湖商用厨具_芜湖厨具设备-芜湖鑫环厨具有限公司 控显科技 - 工控一体机、工业显示器、工业平板电脑源头厂家 | 杰恒蠕动泵-蠕动泵专业厂家-19年专注蠕动泵 | 点胶机_点胶阀_自动点胶机_智能点胶机_喷胶机_点胶机厂家【欧力克斯】 | 不锈钢电动球阀_气动高压闸阀_旋塞疏水调节阀_全立阀门-来自温州工业阀门巨头企业 | 高尔夫球杆_高尔夫果岭_高尔夫用品-深圳市新高品体育用品有限公司 | 北京租车公司_汽车/客车/班车/大巴车租赁_商务会议/展会用车/旅游大巴出租_北京桐顺创业租车公司 | 广东泵阀展|阀门展-广东国际泵管阀展览会 | 订做不锈钢_不锈钢定做加工厂_不锈钢非标定制-重庆侨峰金属加工厂 | 丹佛斯变频器-Danfoss战略代理经销商-上海津信变频器有限公司 | 乐泰胶水_loctite_乐泰胶_汉高乐泰授权(中国)总代理-鑫华良供应链 | Brotu | 关注AI,Web3.0,VR/AR,GPT,元宇宙区块链数字产业 | 山东艾德实业有限公司| 浙江自考_浙江自学考试网 |