Page 1 of 1

SQL left JOIN - HOW TO ACHIEVE IT THROUGH AHK

Posted: 05 Feb 2017, 11:24
by sv270190
TWO FILES ARE THERE

F1.TXT

AC|NAME
1|RAM
2|RAHIM
3|ROBERT
4|guru
5|raju

F2. TXT

AC|AMOUNT
1|100
2|200
3|300

WHAT I WANT TO ACHIEVE

F3.TXT

AC|NAME|AMOUNT
1|RAM|100
2|RAHIM|200
3|ROBERT|300
4|guru|
5|raju|

I could achieve the following:

AC|NAME|AMOUNT
1|RAM|100
2|RAHIM|200
3|ROBERT|300

through this code


#SingleInstance FORCE
filedelete, f0*.txt
Loop, Read, F1.TXT
{
f1line := A_LoopReadLine
StringSplit, z, f1line,|
; msgbox %z1%%z2%%z3% ; so far ok

loop, read,f2.txt,f03.txt
{
var1 =
f2line := A_LoopReadLine
stringsplit,y,f2line,|
if y1 = %z1%
{
var1 = %y1%|%y2%

fileappend,%var1%|%z1%|%z2%`n
}
}


}

return



your help will be highly appreciated

Re: SQL left JOIN - HOW TO ACHIEVE IT THROUGH AHK

Posted: 05 Feb 2017, 15:16
by HotKeyIt

Code: Select all

F1=
(
AC|NAME
1|RAM
2|RAHIM
3|ROBERT
4|guru
5|raju
)
F2=
(
AC|AMOUNT
1|100
2|200
3|300
)
oF1:=[]
oF2:=[]
Loop,Parse,F1,`n,`r
   If A_Index=1
      F3:=A_LoopField
   else
      o:=StrSplit(A_LoopField,"|"),oF1[o.1]:=o.2

Loop,Parse,F2,`n,`r
   If A_Index=1
      F3.=SubStr(A_LoopField,InStr(A_LoopField, "|")) "`r`n"
   else
      o:=StrSplit(A_LoopField,"|"),oF2[o.1]:=o.2

for k,v in oF1
   F3.=k "|" v "|" oF2[k] "`r`n"

F3:=RTrim(F3,"`r`n")

MsgBox % F3

Re: SQL left JOIN - HOW TO ACHIEVE IT THROUGH AHK

Posted: 06 Feb 2017, 21:02
by sv270190
Good. It works.
But sir I could not understand your code
What why
What should I read?
Arrays / objects ??

Re: SQL left JOIN - HOW TO ACHIEVE IT THROUGH AHK

Posted: 06 Feb 2017, 21:02
by sv270190
Thank you

Re: SQL left JOIN - HOW TO ACHIEVE IT THROUGH AHK

Posted: 06 Feb 2017, 21:06
by sv270190
Thank you
Could you convert this as function
For eg
AHK_LEFT_JOIN(F1, F2, F1C, F2C)