create cursor master1 (weight n(8,2), qty n(8),pr_qty n(13),rr_qty n(13),; c_qty n(13),cr_qty n(13),c_amount n(13),cr_amount n(13),dr_qty n(10)) select master1 append from dbf('master') for substr(code, 1, 2)='32' .and. len(alltrim(code))=7 and !deleted() select master1 acccode = space(7) select crsalp goto top scan acccode = acc_code store 0 to qty1, qty2 if date<f_date1 qty1 = qty endif if date>=f_date1 .and. date<=t_date1 qty2 = qty endif select master1 goto top seek alltrim(acccode) if found() replace cr_qty with cr_qty+qty1, credit with credit+qty2 endif select crsalp endscanI want to convert it into sqlserver query,
** in case of single date cmd="select distinct(acc_code)as acc_code, SUM(qty)as qty from crsalp where date <?m.f_date1 group by acc_code order by acc_code" if sqlexec(con,cmd,'table1')<0 aerror(laerror) messagebox(laerror[1,2]) return.f. endif select table1 go top scan text TO m.cmd NOSHOW TEXTMERGE PRETEXT 7 INSERT INTO master1(cr_qty,credit)values(?cr_qty+?qty,?credit+?qty2) ENDTEXT if sqlexec(m.con,cmd)<0 aerror(laerror) messagebox(laerror[1,2]) lok=.f. return.f. endif endscan ** in case of between date cmd="select distinct(acc_code)as acc_code, SUM(qty)as qty from crsalp where date between ?m.f_date1 and ?m.t_date1 group by acc_code order by acc_code" if sqlexec(con,cmd,'table2')<0 aerror(laerror) messagebox(laerror[1,2]) return.f. endif select table2 go top scan text TO m.cmd NOSHOW TEXTMERGE PRETEXT 7 INSERT INTO master1(cr_qty,credit)values(?cr_qty+?qty,?credit+?qty2) ENDTEXT if sqlexec(m.con,cmd)<0 aerror(laerror) messagebox(laerror[1,2]) lok=.f. return.f. endif ENDSCANBut these codes has errors,