| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 855 人关注过本帖
标题:谁能帮我看看这个SQL哪错了?
只看楼主 加入收藏
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
结帖率:87.5%
收藏
已结贴  问题点数:10 回复次数:3 
谁能帮我看看这个SQL哪错了?
初次使用oracle ,下面的语句是从SQL Server转过来的,我不知道哪错了,调了半天,总是报a1.SH_Code 列名无效? 下面的语句有点长,还希望会oracle 的朋友们能耐心帮我看看,感激不尽,我真的找不出来错,改不好。

select cr_code,
       cr_name,
       SH_Code,
       SH_Name,
       We_Code,
       We_Name,
       Wec_ID,
       Wec_Name,
       SnD_WC_Color,
       SnD_WM_Model,
       We_Spec,
       SnD_Ut_ID,
       Ut_Name,
       nvl(in_Qtys, 0) as Qty,
       nvl(Out_Qtys, 0) as out_Qty,
       nvl(Qty, 0) as ptd_Qty
  from (select distinct cr_code,
                        cr_name,
                        SH_Code,
                        SH_Name,
                        We_Code,
                        We_Name,
                        Wec_ID,
                        Wec_Name,
                        WC_Color as SnD_WC_Color,
                        WM_Model as SnD_WM_Model,
                        We_Spec,
                        Ut_ID as SnD_Ut_ID,
                        Ut_Name,
                        (select sum(SnD_Qty) as in_Qtys
                           from (select distinct SnD_Qty,
                                                 StdIn_Detail.SnD_We_Code,
                                                 StdIn_Detail.SnD_WC_Color,
                                                 StdIn_Detail.SnD_WM_Model,
                                                 Sn_StdIn_Code
                                   from StdIn, StdIn_Detail, In_Orders
                                  where Sn_StdIn_Code = SnD_StdIn_Code
                                    and Sn_InO_Code = InO_Code
                                    and to_char(StdIn.CreateDate, 'yyyy-mm-dd') >=
                                        to_char('', 'yyyy-mm-dd')
                                    and to_char(StdIn.CreateDate, 'yyyy-mm-dd') <=
                                        to_char('', 'yyyy-mm-dd')
                                    and StdIn_Detail.SnD_We_Code = a1.We_Code
                                    and nvl(StdIn_Detail.SnD_WC_Color, '') =
                                        nvl(a1.WC_Color, '')
                                    and nvl(StdIn_Detail.SnD_WM_Model, '') =
                                        nvl(a1.WM_Model, '')
                                    and InO_Cr_Code = a1.Cr_Code
                                    and InO_SH_Code = a1.Sh_Code) AA
                          group by SnD_We_Code, SnD_WC_Color, SnD_WM_Model) in_Qtys,
                        (select nvl(sum(StD_Qty), 0) as out_Qty
                           from (select distinct StD_Qty,
                                                 StD_Ware_Code,
                                                 StD_WC_Color,
                                                 StD_WM_Model,
                                                 StD_StdOut_Code
                                   from StdOut_Detail b,
                                        StdOut        b1,
                                        Out_Orders    b2
                                  where b.StD_StdOut_Code = b1.St_StdOut_Code
                                    and b1.St_OutO_Code = b2.OutO_Code
                                    and b1.St_Status = 1
                                    and to_char(b1.CreateDate, 'yyyy-mm-dd') >=
                                        to_char('yyyy-mm-dd')
                                    and to_char(b1.CreateDate, 'yyyy-mm-dd') <=
                                        to_char('', 'yyyy-mm-dd')
                                    and b.StD_Ware_Code = a1.We_Code
                                    and b2.OutO_SH_Code = a1.Sh_Code
                                    and nvl(b.StD_WC_Color, '') =
                                        nvl(a1.WC_Color, '')
                                    and nvl(b.StD_WM_Model, '') =
                                        nvl(a1.WM_Model, '')
                                    and b2.OutO_Cr_Code = a1.cr_code) DD
                          group by StD_Ware_Code, StD_WC_Color, StD_WM_Model) Out_Qtys,
                        (select sum(Ptd_Qty) as Qty
                           from (select distinct Ptd_StdIn_Code,
                                                 Ptd_Pt_Code,
                                                 Ptd_We_Code,
                                                 Ptd_Qty,
                                                 Ptd_WC_Color,
                                                 Ptd_WM_Model
                                   from Pallet_Detail,
                                        Pallet_Use_Detail,
                                        StdIn,
                                        In_Orders
                                  where Ptd_Ptud_ID = Ptud_ID
                                    and Ptud_Status <> 2
                                    and Ptd_StdIn_Code = Sn_StdIn_Code
                                    and Sn_InO_Code = InO_Code
                                    and Ptud_Sh_Code = a1.Sh_Code
                                    and InO_Cr_Code = a1.cr_code
                                    and Ptd_We_Code = a1.We_Code  /*无效列名*/
                                    and nvl(Ptd_WC_Color, '') =
                                        nvl(a1.WC_Color, '')
                                    and nvl(Ptd_WM_Model, '') =
                                        nvl(a1.WM_Model, '')) gg
                          group by Ptd_We_Code, Ptd_WC_Color, Ptd_WM_Model) Qty
          from (select distinct SH_Code,
                                SH_Name,
                                cr_code,
                                cr_name,
                                We_Code,
                                We_Name,
                                Wec_ID,
                                Wec_Name,
                                WC_Color,
                                WM_Model,
                                We_Spec,
                                Ut_ID,
                                Ut_Name
                  from (select distinct SH_Code,
                                        SH_Name,
                                        cr_code,
                                        cr_name,
                                        We_Code,
                                        We_Name,
                                        Wec_ID,
                                        Wec_Name,
                                        SnD_WC_Color as WC_Color,
                                        SnD_WM_Model as WM_Model,
                                        We_Spec,
                                        Ut_ID,
                                        Ut_Name
                          from StdIn,
                               StdIn_Detail,
                               In_Orders,
                               In_Orders_Detail,
                               Customer,
                               Ware,
                               Ware_Category,
                               Store_House,
                               Unit
                         where InO_SH_Code = SH_Code
                           and Sn_StdIn_Code = SnD_StdIn_Code
                           and Sn_InO_Code = InO_Code
                           and InO_Code = InOD_InO_Code
                           and InO_Cr_Code = Cr_Code
                           and SnD_We_Code = We_Code
                           and We_Wec_ID = Wec_ID
                           and SnD_Ut_ID = Ut_ID
                           and Sn_Status = 1
                           and to_char(StdIn.CreateDate, 'yyyy-mm-dd') >=
                               to_char('', 'yyyy-mm-dd')
                           and to_char(StdIn.CreateDate, 'yyyy-mm-dd') <=
                               to_char('', 'yyyy-mm-dd')
                        union
                        select distinct SH_Code,
                                        SH_Name,
                                        cr_code,
                                        cr_name,
                                        We_Code,
                                        We_Name,
                                        Wec_ID,
                                        Wec_Name,
                                        StD_WC_Color as WC_Color,
                                        StD_WM_Model as WM_Model,
                                        We_Spec,
                                        Ut_ID,
                                        Ut_Name
                          from StdOut,
                               StdOut_Detail,
                               Out_Orders,
                               Customer,
                               Ware,
                               Ware_Category,
                               Store_House,
                               Unit
                         where St_StdOut_Code = StD_StdOut_Code
                           and St_OutO_Code = OutO_Code
                           and OutO_Cr_Code = cr_code
                           and StD_Ware_Code = We_Code
                           and We_Wec_ID = Wec_ID
                           and St_SH_Code = Sh_Code
                           and StD_Ut_ID = Ut_ID
                           and St_Status = 1
                           and to_char(StdOut.CreateDate, 'yyyy-mm-dd') >=
                               to_char('', 'yyyy-mm-dd')
                           and to_char(StdOut.CreateDate, 'yyyy-mm-dd') <=
                               to_char('', 'yyyy-mm-dd')) a) a1) a2
搜索更多相关主题的帖子: SQL 
2010-09-25 10:26
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
收藏
得分:0 
凡带a1.什么什么的都提示,无效列名,我把带a1.什么什么的条件都去掉,它就对了。 这是为什么啊?

有没人帮我看看啊
2010-09-25 10:45
流星雨
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:JAVA风暴
等 级:版主
威 望:43
帖 子:1854
专家分:1868
注 册:2004-5-30
收藏
得分:10 
我没看语句,太长了,但是如果是A1,那边报错,无效列名,明显,就是没有那几个列。
A1是你给一张表起的别名,看看那张表有没有那个列就是了。

感谢你们带我找到星空下美丽神话,无论经历多少苦痛也不放弃的梦;插上希望翅膀乘风我和你们飞翔,飞过海天尽头携手把梦想实现.....
2010-09-26 22:54
amwihdyt2011
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-2-17
收藏
得分:0 
別名錯了吧
2011-06-29 03:39
快速回复:谁能帮我看看这个SQL哪错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019517 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved