| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4965 人关注过本帖
标题:SQL代码运行不了,求指教
取消只看楼主 加入收藏
awinna
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-9-1
收藏
得分:0 
回复 15楼 mywisdom88
我只想要结果显示成,待签收或已签收。代码中除了as后面的汉字,都要'''',才能正常。用的sql server 2012,看到都是加一个'',不知为何。至于您说的oracle,小菜鸟我也是不明白怎样转去的
2016-09-20 22:31
awinna
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-9-1
收藏
得分:0 
回复 17楼 mywisdom88
把 ''待签收'' 改为 '''待签收''',加上3个'',代码会出现波浪线,提示出错,运行也出错。
 无论是
 (SELECT DECODE(sod.sigininstate,1,''待签收'',''已签收'') from YLHT.tb_ope_sigininorder sod
                                                            where sod.taskorderno =R.taskorderno
                                                              and sod.state = 1
                                                              and rownum=1)as 签收状态,
还是
(SELECT DECODE(sod.sigininstate,1,'''待签收''','''已签收''') from YLHT.tb_ope_sigininorder sod
                                                            where sod.taskorderno =R.taskorderno
                                                              and sod.state = 1
                                                              and rownum=1)as 签收状态,
都会出错。
下面这两句句可以正确运行
DECODE(R.AIRBILLCOLLECTION, 1, ''拼单'', 0, ''主单'') AS 是否拼票,
 decode(R.issplitorder,0,''母单'',''子单'') as 母子单
2016-09-22 09:30
awinna
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-9-1
收藏
得分:0 
SELECT  * FROM OPENQUERY (YLHT,'
SELECT
 (SELECT DECODE(sd.sigininstate,1,''待签收'',''已签收'') from YLHT.tb_ope_sigininorder sd
                                                            where sd.taskorderno =R.taskorderno
                                                              and sd.state = 1
                                                              and rownum=1) as 签收状态
                                         FROM YLHT.TB_SALE_TASKORDER R
')
go
这样单独测试可以运行出结果
签收状态
已签收
下面的语句加上这一句就不可以正确运行了
IF EXISTS(SELECT * FROM SYSOBJECTS WHERE NAME ='V_TASK_REPORT_TIMELY')
DROP VIEW V_TASK_REPORT_TIMELY
GO

CREATE  VIEW V_TASK_REPORT_TIMELY
AS
select * from openquery(YLHT,'
SELECT
       R.consigndate as 托运日期,
       R.TASKORDERNO    任务单号,
       R.printorderno as 分单号,
       R.waybill as 主单号,
      
       (select sum(nvl(g.prepieceqty,0)) from YLHT.tb_sale_taskorder_goodsdetail g where g.taskorderno=R.taskorderno) as 总预计件数,
       (select sum(nvl(tg.preweight, 0)) from YLHT.tb_sale_taskorder_goodsdetail tg
                                        where tg.taskorderno = R.taskorderno) as 总预计重量,
       (select sum(greatest (nvl(tg.convertplanweight, 0) ,nvl(tg.preweight, 0) ,nvl(tg.convertweight, 0) ))
          from YLHT.tb_sale_taskorder_goodsdetail tg
         where tg.taskorderno = R.taskorderno ) as 总计费重量,
       to_number(NVL(R.REBATEAMOUNT,0)) AS 回扣金额,
       to_number(R.TOTALAMOUNT) AS 总应收,
   
     
       (select p.productname from YLHT.tb_sys_product p where p.productid = R.mainproduct) as 开单干线,
       (select MAX(updatetime) FROM YLHT.tb_buy_assemrecord ar
                                 where ar.type = 1
                                   and ar.state = 2
                                   and ar.taskorderno =R.TASKORDERNO) AS 配载生效时间,        

       (SELECT DECODE(PT.TRANSPORTWAY,1,''空运'',2,''汽运'',3,''铁运'',''其他'') AS 运输方式
          FROM YLHT.TB_SYS_PRODUCT PT
         WHERE PT.PRODUCTID =(SELECT RDD.TASKPRODUCTID
                                FROM YLHT.TB_SALE_TASKORDER_ROUTEDETAIL RDD
                               WHERE RDD.ROUTEORDER =NVL((SELECT MIN(RD.ROUTEORDER)
                                                            FROM YLHT.TB_SALE_TASKORDER_ROUTEDETAIL RD
                                                           WHERE RD.TASKORDERNO = R.TASKORDERNO
                                                             AND RD.ROUTETYPE = 3
                                                             AND RD.ROWSTATE <> 0),
                                                            -1)
                                 AND RDD.TASKORDERNO = R.TASKORDERNO
                                 AND RDD.ROUTETYPE = 3
                                 AND RDD.ROWSTATE <> 0
                                 AND ROWNUM = 1)) AS 实际运输方式,
      nvl((SELECT MIN(D.RESOURCEDATE) AS RESOURCEDATE
                     FROM YLHT.TB_BUY_ASSEMRECORD     AR,
                          YLHT.TB_BUY_ASSEMPLAN       AP,
                          YLHT.TB_BUY_BUYORDER        B,
                          YLHT.TB_BUY_BUYORDER_DETAIL D
                    WHERE AR.STATE > 0
                      AND AP.STATE > 0
                      AND D.ROWSTATE > 0
                      AND AP.ASSEMPLANID = AR.ASSEMPLANID
                      AND B.BUYORDERNO = AR.BUYSCHEDULEORDER
                      AND B.BUYORDERNO = D.BUYORDERNO
                      AND AP.MAINPRODUCT = AR.PRODUCTID
                      AND AR.TASKORDERNO = R.TASKORDERNO) ,
                  (SELECT MIN(SD.VALIDDATE) AS RESOURCEDATE
                     FROM YLHT.TB_BUY_ASSEMRECORD    AR,
                          YLHT.TB_BUY_ASSEMPLAN      AP,
                          YLHT.TB_SALE_SCHEDULEORDER SD
                    WHERE AR.STATE > 0
                      AND AP.STATE > 0
                      AND AP.ASSEMPLANID = AR.ASSEMPLANID
                      AND AP.MAINPRODUCT = AR.PRODUCTID
                      AND AR.TASKORDERNO = R.TASKORDERNO
                      AND AR.BUYSCHEDULEORDER = SD.SCHEDULEORDERNO) ) as 出港日期,
       DECODE(R.GOODSCONTROL,1,''物控'',0,''不物控'') AS 物控,
    (SELECT WM_CONCAT(TBA.BUYSCHEDULEORDER)
          FROM YLHT.TB_SALE_TASKORDER_ROUTEDETAIL TSTR
         INNER JOIN YLHT.TB_BUY_ASSEMRECORD TBA
                 ON TBA.TASKORDERNO= TSTR.TASKORDERNO
                AND TBA.PRODUCTID = TSTR.TASKPRODUCTID
         WHERE TBA.TASKORDERNO =R.TASKORDERNO
           AND TSTR.ROUTETYPE = 3
           AND TSTR.ROWSTATE > 0
           AND TBA.STATE > 0
         GROUP BY TSTR.TASKORDERNO) AS 采购单号,
       CASE WHEN R.TASKTYPE>=8 THEN
               (SELECT NETPOINTNAME FROM YLHT.TB_BASE_NETPOINT NET WHERE )
       ELSE (select c.customername from YLHT.tb_buy_assemrecord ar,
                                        YLHT.tb_buy_assemplan ap,
                                        YLHT.tb_sys_customer c
                                  where ar.state > 0
                                    and ap.state(+) > 0
                                    and ap.assemplanid(+) = ar.assemplanid
                                    and ar.taskorderno = R.TASKORDERNO
                                    and ar.routeorder = (select max(rd.routeorder)
                                                           from YLHT.tb_sale_taskorder_routedetail rd
                                                          where rd.taskorderno = ar.taskorderno
                                                            and rd.rowstate > 0
                                                            and rd.routetype in (5,6))
                                                            and c.customerid = ar.customerid
                                                            and rownum = 1)
        END AS 实际提派代理,
   


       (select from YLHT.tb_base_netpoint n where ) as 始发站,
       (select from YLHT.tb_base_netpoint n where ) as 中转站,
       (select from YLHT.tb_base_netpoint n where ) as 目的站,
       (select from YLHT.tb_base_netpoint n where ) as 来源网点,
       (SELECT NETPOINTNAME FROM YLHT.TB_BASE_NETPOINT NET WHERE ) AS 目的网点,
       (SELECT C.CUSTOMERNAME FROM YLHT.TB_SYS_CUSTOMER C WHERE C.CUSTOMERID = R.SENDAGENCY) AS 开单提派代理,
   
       (select c1.customername from YLHT.tb_sys_customer c1  where c1.customerid = R.customerid ) as 客商名称,

       (select from YLHT.tb_sys_org s where R.deptid=) as 受理部门,
     
   
           
       (select u1.username from YLHT.tb_sys_user u1 where R.salesman = u1.userid and u1.state>0 and rownum=1) as 业务员,
      
      
       decode(c.changetype,1,''基本信息变更'',''退返转变更'')  as 变更类型,
     (select sod.siginindate from YLHT.tb_ope_sigininorder sod
                             where sod.taskorderno=R.taskorderno
                               and sod.state = 1
                               and rownum=1) as 实际签收时间,
                               (select sod.sigininenteringdate from YLHT.tb_ope_sigininorder sod
                                     where sod.taskorderno =R.taskorderno
                                       and sod.state = 1
                                       and rownum=1)as 签收录入时间,

      
       R.createtime as 任务单制单时间,
        (SELECT DECODE(sod.sigininstate,1,''待签收'',''已签收'') from YLHT.tb_ope_sigininorder sod
                                                            where sod.taskorderno =R.taskorderno
                                                              and sod.state = 1
                                                              and rownum=1)as 签收状态,  --就是这句有问题

       DECODE(R.AIRBILLCOLLECTION, 1, ''拼单'', 0, ''主单'') AS 是否拼票,
       decode(R.issplitorder,0,''母单'',''子单'') as 母子单

  FROM YLHT.TB_SALE_TASKORDER R
       LEFT JOIN  YLHT.tb_sys_customer CU ON CU.CUSTOMERID=R.CUSTOMERID
       left join YLHT.tb_sale_taskorderchange c
              on c.taskorderid=R.taskorderid
             and c.goodscontrol2 is not null
             and c.state=7
             and c.createtime IN (select max(tc.createtime)
                                    from YLHT.tb_sale_taskorderchange tc
                                   where tc.taskorderid = R.taskorderid
                                   group by tc.taskorderid)
 WHERE R.STATE<>1
  AND R.CONSIGNDATE>=to_date(''2015-10-06'',''yyyy-mm-dd'')
  
   ')
   GO
   SELECT * FROM V_TASK_REPORT_TIMELY
2016-09-23 10:40
awinna
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-9-1
收藏
得分:0 
错误提示为
消息 103,级别 15,状态 1,过程 V_TASK_REPORT_TIMELY,第 4 行
以 '
SELECT
       R.consigndate as 托运日期,
       R.TASKORDERNO    任务单号,
       R.printorderno as 分单号,
       R.waybill as 主单号,
' 开头的 字符串 太长。最大长度为 8000。
消息 208,级别 16,状态 1,第 1 行
对象名 'V_TASK_REPORT_TIMELY' 无效。
2016-09-23 10:42
awinna
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-9-1
收藏
得分:0 
(select sod.siginindate from YLHT.tb_ope_sigininorder sod
                             where sod.taskorderno=R.taskorderno
                               and sod.state = 1
                               and rownum=1) as 实际签收时间,
                               (select sod.sigininenteringdate from YLHT.tb_ope_sigininorder sod
                                     where sod.taskorderno =R.taskorderno
                                       and sod.state = 1
                                       and rownum=1)as 签收录入时间,

      (SELECT DECODE(sod.sigininstate,1,''待签收'',''已签收'') from YLHT.tb_ope_sigininorder sod
                                                            where sod.taskorderno =R.taskorderno
                                                              and sod.state = 1
                                                              and rownum=1)as 签收状态,
最新测试是
这三个字段任意选两个都可以运行,如果全选就会出错,求解,谢谢
2016-09-29 09:22
awinna
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-9-1
收藏
得分:0 
回复 21楼 awinna
减少缩进,就可以了,真是涨见识了
2016-09-29 09:31
awinna
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-9-1
收藏
得分:0 
回复 24楼 厨师王德榜
代码是很久以前未见过的同事写的,只是现在换了一个链接端口,链接的物流系统中的表内容不同但表的格式是一样的。
现在的问题更麻烦了,目测19楼只是中的代码差不多只是全部代码中的一半,剩下的寸步难行,伤不起
2016-09-29 14:00
快速回复:SQL代码运行不了,求指教
数据加载中...
 
   



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

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