modify sql statement from *= to left outer join

  • I am trying to convert to left outer join syntax a sql statement that works as expected using *= syntax.

    current sql

    SELECT labtrans.transdate,

    labtrans.laborcode,

    labtrans.regularhrs,

    labtrans.startdate,

    labtrans.craft,

    labtrans.refwo,

    task.worktype,

    task.parent,

    parent.wonum,

    parent.location,

    parent.worktype,

    matusetrans.itemnum,

    matusetrans.mrnum,

    matusetrans.transdate,

    matusetrans.actualdate,

    matusetrans.issuetype,

    matusetrans.description,

    matusetrans.storeloc,

    matusetrans.refwo,

    matusetrans.linetype,

    labor.personid,

    matusetrans.issueto,

    asset.eq1

    FROM labtrans,

    workorder task,

    workorder parent,

    labor,

    matusetrans,

    asset

    WHERE ( labtrans.refwo = task.wonum ) and

    ( task.parent = parent.wonum ) and ( labtrans.laborcode = labor.laborcode ) and

    ( labtrans.refwo *= matusetrans.refwo) and

    (convert (char( 20 ),labtrans.startdate,6) *= convert (char( 20 ),matusetrans.transdate,6)) and

    (matusetrans.linetype = 'WAREHOUSE ITEM' or matusetrans.linetype = 'TOOL ROOM') and

    (labor.personid *= matusetrans.issueto) and (parent.worktype <> 'A') and

    (labtrans.craft >= '611-ELEC' and labtrans.craft <= '619-SMWE') and (task.assetnum *= asset.assetnum) and

    ( labtrans.startdate >= :from_date and labtrans.startdate <= :thru_date )

    conversion so far....

    SELECT labtrans.transdate,

    labtrans.laborcode,

    labtrans.regularhrs,

    labtrans.startdate,

    labtrans.craft,

    labtrans.refwo,

    task.worktype,

    task.parent,

    parent.wonum,

    parent.location,

    parent.worktype,

    matusetrans.itemnum,

    matusetrans.mrnum,

    matusetrans.transdate,

    matusetrans.actualdate,

    matusetrans.issuetype,

    matusetrans.description,

    matusetrans.storeloc,

    matusetrans.refwo,

    matusetrans.linetype,

    labor.personid,

    matusetrans.issueto,

    asset.eq1

    FROM { oj labtrans left outer join matusetrans ON ( labtrans.refwo = matusetrans.refwo) and

    (convert (char( 20 ),labtrans.startdate,6) = convert (char( 20 ),matusetrans.transdate,6)) and

    (matusetrans.linetype = 'WAREHOUSE ITEM' or matusetrans.linetype = 'TOOL ROOM')} ,

    { oj workorder task left outer join asset ON (task.assetnum = asset.assetnum) } ,

    workorder parent,

    labor

    WHERE ( labtrans.refwo = task.wonum ) and

    ( task.parent = parent.wonum ) and

    (parent.worktype <> 'A') and

    (labtrans.laborcode = labor.laborcode) and

    (labor.personid *= matusetrans.issueto) and

    (labtrans.craft >= '611-ELEC' and labtrans.craft <= '619-SMWE') and

    ( labtrans.startdate >= :from_date and labtrans.startdate <= :thru_date )

    I haven't successfully converted the left outer join of the labor and matusetrans tables.

    I need to join labtrans to labor to have a data column that will join with matusetrans.

    If I alias matusetrans {oj labor left outer join matusetrans issue on labor.personid = issue.issueto} I don't get a syntax error

    but I am not getting what I want.

    Thanks for any help.

    Carol

  • Are you running this through somehting other than Microsoft SQL server? "{of" is not somehting SQL would understand to my knowledge. Also you have spaces in your table names which would have to be in cased in [].

    Dan

    If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.

  • I'm sure you're not using SQL Server, but I guess this should work as expected.

    SELECT labtrans.transdate,

    labtrans.laborcode,

    labtrans.regularhrs,

    labtrans.startdate,

    labtrans.craft,

    labtrans.refwo,

    task.worktype,

    task.parent,

    parent.wonum,

    parent.location,

    parent.worktype,

    matusetrans.itemnum,

    matusetrans.mrnum,

    matusetrans.transdate,

    matusetrans.actualdate,

    matusetrans.issuetype,

    matusetrans.description,

    matusetrans.storeloc,

    matusetrans.refwo,

    matusetrans.linetype,

    labor.personid,

    matusetrans.issueto,

    asset.eq1

    FROM labtrans

    JOIN workorder task ON labtrans.refwo = task.wonum

    JOIN workorder parent ON task.parent = parent.wonum

    JOIN labor ON labtrans.laborcode = labor.laborcode

    LEFT JOIN matusetrans ON labtrans.refwo = matusetrans.refwo

    AND convert (char( 20 ),labtrans.startdate,6) = convert (char( 20 ),matusetrans.transdate,6)

    AND (matusetrans.linetype = 'WAREHOUSE ITEM' or matusetrans.linetype = 'TOOL ROOM')

    AND labor.personid = matusetrans.issueto

    LEFT JOIN asset ON task.assetnum = asset.assetnum

    WHERE (parent.worktype <> 'A') and

    (labtrans.craft >= '611-ELEC' and

    labtrans.craft <= '619-SMWE') and

    ( labtrans.startdate >= :from_date and labtrans.startdate <= :thru_date )

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • thanks that works.

    the syntax I provided {oj } was default syntax created when using powerbuilder graphic interface and then converting to syntax.

    That's where the *= came from. I am using sql server so if that is unusual i guess it is a powerbuilder thing.

    I have used the {oj } syntax in other places and it is working fine.

    Thanks so much for your help.

  • There might be something wrong in the configuration of Powerbuilder (I've never used it). The variables are wrong as well (there's a : where a @ should go).

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply