Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert Scan --- Endscan into SQLSERVER query
Message
From
23/08/2016 01:14:37
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Convert Scan --- Endscan into SQLSERVER query
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP
Network:
Windows XP
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01639781
Message ID:
01639781
Views:
69
Sir I have these codes
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
endscan
I want to convert it into sqlserver query,
For that I made an attempt like this
** 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

ENDSCAN
But these codes has errors,
Please help me to convert SCAN --- ENDSCAN
Reply
Map
View

Click here to load this message in the networking platform