Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

modify sql statement from *= to left outer join Expand / Collapse
Author
Message
Posted Thursday, September 19, 2013 7:17 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 17, 2013 7:54 AM
Points: 2, Visits: 12
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
Post #1496379
Posted Thursday, September 19, 2013 9:25 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, October 28, 2013 8:10 AM
Points: 822, Visits: 1,198
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.
Post #1496458
Posted Thursday, September 19, 2013 9:55 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:34 PM
Points: 2,788, Visits: 5,973
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.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1496475
Posted Thursday, September 19, 2013 12:10 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 17, 2013 7:54 AM
Points: 2, Visits: 12
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.
Post #1496539
Posted Thursday, September 19, 2013 12:32 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:34 PM
Points: 2,788, Visits: 5,973
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.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1496549
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse