Thanks for you advice.
I have tried your second option to obtain the last partOper.
Main and sub query run on their own but when joined together it runs forever. I think my test virtual machine 1GB RAM can't handle it so I will upgarde it and try again.
I will also try your first contribution.Really apprecaited.
Once again thank you
Michael
I have tried your second option to obtain the last partOper.
Main and sub query run on their own but when joined together it runs forever. I think my test virtual machine 1GB RAM can't handle it so I will upgarde it and try again.
I will also try your first contribution.Really apprecaited.
Once again thank you
Michael
--- In vantage@yahoogroups.com, Mark Wonsil <mark_wonsil@...> wrote:
>
> > I am running Vantage 803.409C and due recent increase in data database is unable to handle the volume. I am now using SQL server to run the BIG reports but I am now stuck with a BAQ where I anm unable to implement FIRST or LAST in TSQL as shown below in dotted line
> > The first part of the BAQ run perfect and am now looking for how to
> > join the last bit. Please help. Thanks
> >
> > Below is the BAQ:
> > for each JobHead no-lock , each JobAsmbl where (JobHead.Company = JobAsmbl.Company and JobHead.JobNum = JobAsmbl.JobNum) no-lock , each LaborDtl outer-join where (JobAsmbl.Company = LaborDtl.Company and JobAsmbl.JobNum = LaborDtl.JobNum and JobAsmbl.AssemblySeq = LaborDtl.AssemblySeq) no-lock , each Part where (JobHead.Company =
> > Part.Company and JobHead.PartNum = Part.PartNum) no-lock ,
> > ----------------------------------------------------------
> > LAST PartOpr where (Part.Company = PartOpr.Company and Part.PartNum = PartOpr.PartNum) no-lock by JobAsmbl.JobNum by LaborDtl.OprSeq by LaborDtl.ClockInDate.
> >
>
> I'm not an T-SQL expert but the way I remember people dealing with
> this is with a sub-query:
>
> (SELECT TOP 1 PartOpe from blah blah where blah blah order by blah
> blah DESC) as LastOper
>
> The trick is to select the top record by sorting in reverse order. The
> other way is to use the MAX operator if you know the data will allow
> it but here you're looking for an operation number and not a date.
>
> Mark W.
>