Correct error

Hi,
what to adjust below

select p.ctrsfno, w.cothername ccustcode, 'HKD' currency, p.ttrsfdate tinvdate, date_add(p.ttrsfdate,interval 1 day) tinvdate2, p.ttrsfdate txndate, '' dbgroup, '' cpayterm, 0 ndisrate, 0 ddisamt, if(br.ncorpno=1,'S-KC', 'S-CL') cloccode, '' ccusordno, '' csalordno, 0 naccqty, '' citem, b.ccode, b.csize, 'HKD' currcode,c.nqty * -1 nitemqty, s.nbrandno, br.ncorpno companycode, s.ntype, s.dcost, c.nqty * -1 * s.dcost damount, p.nwareno, w.cshort2 shopcode,w.cname shopname,w.cothername clientcode,br.cbrandname cbrand from gal00001_s_consolid.trsf_p p inner join gal00001_s_consolid.trsf_c c on p.ctrsfno = c.ctrsfno inner join gal00001_s_consolid.dbf_warehse w on w.nwareno = p.nwareno inner join gal00001_s_consolid.dbf_barcode b on b.cbarcode = c.cbarcode inner join gal00001_s_consolid.dbf_stk_info s on s.ccode = b.ccode inner join gal00001_s_consolid.dbf_brand br on br.nbrandno = s.nbrandno where p.ctrsfno like 'WHKTT%' and p.ttrsfdate between '2015/10/19' and '2015/10/20' and w.nwaretype in (2,5) and p.ntype=1 and not tvoiddate between '2015/10/19' and '2015/10/20' union all select p.ctrsfno, w.cothername ccustcode, 'HKD' currency, p.ttrsfdate tinvdate, date_add(p.ttrsfdate,1) tinvdate2, p.ttrsfdate txndate, '' dbgroup, '' cpayterm, 0 ndisrate, 0 ddisamt, if(br.ncorpno=1,'S-KC', 'S-CL') cloccode, '' ccusordno, '' csalordno, 0 naccqty, '' citem, b.ccode, b.csize, 'HKD' currcode,c.nqty * -1 nitemqty, s.nbrandno, br.ncorpno companycode, s.ntype, s.dcost, c.nqty * -1 * s.dcost damount, p.nwareno, w.cshort2 shopcode,w.cname shopname,w.cothername clientcode,br.cbrandname cbrand from sm000001_s_consolid.trsf_p p inner join sm000001_s_consolid.trsf_c c on p.ctrsfno = c.ctrsfno inner join sm000001_s_consolid.dbf_warehse w on w.nwareno = p.nwareno inner join sm000001_s_consolid.dbf_barcode b on b.cbarcode = c.cbarcode inner join sm000001_s_consolid.dbf_stk_info s on s.ccode = b.ccode inner join sm000001_s_consolid.dbf_brand br on br.nbrandno = s.nbrandno where p.ctrsfno like 'WHKTT%' and p.ttrsfdate between '2015/10/19' and '2015/10/20' and w.nwaretype in (2,5) and p.ntype=1 and not tvoiddate between '2015/10/19' and '2015/10/20' order by ctrsfno,ccustcode,ccode

Open in new window

due to such error?

0	18:29:23	select p.ctrsfno, w.cothername ccustcode, 'HKD' currency, p.ttrsfdate tinvdate, date_add(p.ttrsfdate,interval 1 day) tinvdate2, p.ttrsfdate txndate, '' dbgroup, '' cpayterm, 0 ndisrate, 0 ddisamt, if(br.ncorpno=1,'S-KC', 'S-CL') cloccode, '' ccusordno, '' csalordno, 0 naccqty, '' citem, b.ccode, b.csize, 'HKD' currcode,c.nqty * -1 nitemqty, s.nbrandno, br.ncorpno companycode, s.ntype, s.dcost, c.nqty * -1 * s.dcost damount, p.nwareno, w.cshort2 shopcode,w.cname shopname,w.cothername clientcode,br.cbrandname cbrand from gal00001_s_consolid.trsf_p p inner join gal00001_s_consolid.trsf_c c on p.ctrsfno = c.ctrsfno inner join gal00001_s_consolid.dbf_warehse w on w.nwareno = p.nwareno inner join gal00001_s_consolid.dbf_barcode b on b.cbarcode = c.cbarcode inner join gal00001_s_consolid.dbf_stk_info s on s.ccode = b.ccode inner join gal00001_s_consolid.dbf_brand br on br.nbrandno = s.nbrandno where p.ctrsfno like 'WHKTT%' and p.ttrsfdate between '2015/10/19' and '2015/10/20' and w.nwaretype in (2,5) and p.ntype=1 and not tvoiddate between '2015/10/19' and '2015/10/20' union all select p.ctrsfno, w.cothername ccustcode, 'HKD' currency, p.ttrsfdate tinvdate, date_add(p.ttrsfdate,1	Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

Open in new window

LVL 12
HuaMin ChenProblem resolverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pcelbaCommented:
Try this:
select p.ctrsfno, w.cothername ccustcode, 'HKD' currency, p.ttrsfdate tinvdate, date_add(p.ttrsfdate,interval 1 day) tinvdate2, p.ttrsfdate txndate, '' dbgroup, '' cpayterm, 0 ndisrate, 0 ddisamt, if(br.ncorpno=1,'S-KC', 'S-CL') cloccode, '' ccusordno, '' csalordno, 0 naccqty, '' citem, b.ccode, b.csize, 'HKD' currcode,c.nqty * -1 nitemqty, s.nbrandno, br.ncorpno companycode, s.ntype, s.dcost, c.nqty * -1 * s.dcost damount, p.nwareno, w.cshort2 shopcode,w.cname shopname,w.cothername clientcode,br.cbrandname cbrand from gal00001_s_consolid.trsf_p p inner join gal00001_s_consolid.trsf_c c on p.ctrsfno = c.ctrsfno inner join gal00001_s_consolid.dbf_warehse w on w.nwareno = p.nwareno inner join gal00001_s_consolid.dbf_barcode b on b.cbarcode = c.cbarcode inner join gal00001_s_consolid.dbf_stk_info s on s.ccode = b.ccode inner join gal00001_s_consolid.dbf_brand br on br.nbrandno = s.nbrandno where p.ctrsfno like 'WHKTT%' and p.ttrsfdate between '2015/10/19' and '2015/10/20' and w.nwaretype in (2,5) and p.ntype=1 and not tvoiddate between '2015/10/19' and '2015/10/20' union all select p.ctrsfno, w.cothername ccustcode, 'HKD' currency, p.ttrsfdate tinvdate, date_add(p.ttrsfdate, INTERVAL 1 DAY) tinvdate2, p.ttrsfdate txndate, '' dbgroup, '' cpayterm, 0 ndisrate, 0 ddisamt, if(br.ncorpno=1,'S-KC', 'S-CL') cloccode, '' ccusordno, '' csalordno, 0 naccqty, '' citem, b.ccode, b.csize, 'HKD' currcode,c.nqty * -1 nitemqty, s.nbrandno, br.ncorpno companycode, s.ntype, s.dcost, c.nqty * -1 * s.dcost damount, p.nwareno, w.cshort2 shopcode,w.cname shopname,w.cothername clientcode,br.cbrandname cbrand from sm000001_s_consolid.trsf_p p inner join sm000001_s_consolid.trsf_c c on p.ctrsfno = c.ctrsfno inner join sm000001_s_consolid.dbf_warehse w on w.nwareno = p.nwareno inner join sm000001_s_consolid.dbf_barcode b on b.cbarcode = c.cbarcode inner join sm000001_s_consolid.dbf_stk_info s on s.ccode = b.ccode inner join sm000001_s_consolid.dbf_brand br on br.nbrandno = s.nbrandno where p.ctrsfno like 'WHKTT%' and p.ttrsfdate between '2015/10/19' and '2015/10/20' and w.nwaretype in (2,5) and p.ntype=1 and not tvoiddate between '2015/10/19' and '2015/10/20' order by ctrsfno,ccustcode,ccode

Open in new window


And you could also read this article: http://www.codeproject.com/Articles/126380/Writing-Readable-SQL
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PortletPaulfreelancerCommented:
There seems to be a problem around the second IF() so I have changed those IF()s into CASE EXPRESSIONS - and formatted it. Try this please:
SELECT
      p.ctrsfno
    , w.cothername ccustcode
    , 'HKD' currency
    , p.ttrsfdate tinvdate
    , date_add (p.ttrsfdate, interval 1 DAY) tinvdate2
    , p.ttrsfdate txndate
    , '' dbgroup
    , '' cpayterm
    , 0 ndisrate
    , 0 ddisamt
    , CASE WHEN br.ncorpno = 1 THEN 'S-KC' ELSE 'S-CL' END cloccode
    , '' ccusordno
    , '' csalordno
    , 0 naccqty
    , '' citem
    , b.ccode
    , b.csize
    , 'HKD' currcode
    , c.nqty * - 1 nitemqty
    , s.nbrandno
    , br.ncorpno companycode
    , s.ntype
    , s.dcost
    , c.nqty * - 1 * s.dcost damount
    , p.nwareno
    , w.cshort2 shopcode
    , w.cname shopname
    , w.cothername clientcode
    , br.cbrandname cbrand
FROM gal00001_s_consolid.trsf_p p
      INNER JOIN gal00001_s_consolid.trsf_c c ON p.ctrsfno = c.ctrsfno
      INNER JOIN gal00001_s_consolid.dbf_warehse w ON w.nwareno = p.nwareno
      INNER JOIN gal00001_s_consolid.dbf_barcode b ON b.cbarcode = c.cbarcode
      INNER JOIN gal00001_s_consolid.dbf_stk_info s ON s.ccode = b.ccode
      INNER JOIN gal00001_s_consolid.dbf_brand br ON br.nbrandno = s.nbrandno
WHERE p.ctrsfno LIKE 'WHKTT%'
      AND p.ttrsfdate BETWEEN '2015/10/19' AND '2015/10/20'
      AND w.nwaretype IN (2, 5)
      AND p.ntype = 1
      AND NOT tvoiddate BETWEEN '2015/10/19' AND '2015/10/20'

UNION ALL

      SELECT
            p.ctrsfno
          , w.cothername ccustcode
          , 'HKD' currency
          , p.ttrsfdate tinvdate
          , date_add(p.ttrsfdate, 1) tinvdate2
          , p.ttrsfdate txndate
          , '' dbgroup
          , '' cpayterm
          , 0 ndisrate
          , 0 ddisamt
          , CASE WHEN br.ncorpno = 1 THEN 'S-KC' ELSE 'S-CL' END cloccode
          , '' ccusordno
          , '' csalordno
          , 0 naccqty
          , '' citem
          , b.ccode
          , b.csize
          , 'HKD' currcode
          , c.nqty * -1 nitemqty
          , s.nbrandno
          , br.ncorpno companycode
          , s.ntype
          , s.dcost
          , c.nqty * -1 * s.dcost damount
          , p.nwareno
          , w.cshort2 shopcode
          , w.cname shopname
          , w.cothername clientcode
          , br.cbrandname cbrand
      FROM sm000001_s_consolid.trsf_p p
            INNER JOIN sm000001_s_consolid.trsf_c c ON p.ctrsfno = c.ctrsfno
            INNER JOIN sm000001_s_consolid.dbf_warehse w ON w.nwareno = p.nwareno
            INNER JOIN sm000001_s_consolid.dbf_barcode b ON b.cbarcode = c.cbarcode
            INNER JOIN sm000001_s_consolid.dbf_stk_info s ON s.ccode = b.ccode
            INNER JOIN sm000001_s_consolid.dbf_brand br ON br.nbrandno = s.nbrandno
      WHERE p.ctrsfno LIKE 'WHKTT%'
            AND p.ttrsfdate BETWEEN '2015/10/19' AND '2015/10/20'
            AND w.nwaretype IN (2, 5)
            AND p.ntype = 1
            AND NOT tvoiddate BETWEEN '2015/10/19' AND '2015/10/20'
ORDER BY
      ctrsfno
    , ccustcode
    , ccode

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.