Make the first select into derived table and use it in the second one.
Also it's bad idea to use one letter meaningless table aliases because it makes you selects unreadable and hard to maintain.
>>
>*****>First, trying to retrive all datas from JobMaster(JobMast) file with specified
>conditions into cursor temp.
>*****>Then, trying to sum total Qty and Total Amount from the Transactin file (SoTrs) based on
>*****>Qurey result.
>*********************************************
>and Vfp code here
>
>if ThisForm.chk3mth.value=1
> mcond2='month(date())-month(job_salorddt)>3'
>else
> mcond2='!empty(job_salorddt)'
>endif
>
>SalExpDat - Expire date
>SalExpPrd - Expire Period(No.of months)
>
>Sele SalOrdDt As sodate, IIF(SalExpDat)>Date(),Gomonth(SalExpDat,SalExpPrd),SalExpDat) As ExpireDate,SalOrdno as sovno, CusCode as cusno, ;
>IIF(empty(CusCode),JobCustomer,Customer.Cusname) as cusname,;
>Code as jobcode, discount as discamt From jobmast where branch_code= cBranch ;
>and !empty(Salordno) and Jobclose#'C' and jobapproval='A' and &mcond2 into cursor temp
>
>Sele a.so_docno as sovno, ;
>a.so_qty as qty, a.so_price as rate, a.so_discper as disc, a.so_date, sum((a.so_qty-a.so_bkdqty)*a.so_price) as totprice, ;
>sum((a.so_qty-a.so_bkdqty)*a.so_cost) as totcost, b.sodate, b.cusname, b.ref, b.jobcode, b.sman, b.appdt, b.discamt, ;
>iif(ttod(a.so_date)>ttod(b.appdt),"N"," ") as newitm ;
>from sotrs a, temp b where a.so_docno=b.sovno ;
>and a.so_delflag and a.so_qty-a.so_boqty#0 into cursor tempcur group by a.so_docno
>
>Sele tempcur
>brow
>
>I want to just convert it into Sql Server Code.
>
>With thanks and regards
>Abdulla
--sb--