Sunday, February 24, 2008

vbscript to extract data from xdata DDS file (so you don't have to buy M$ Access)

paste the following script into a VBS file (example, x.vbs) and run it with CSCRIPT.EXE from a command prompt (1st argument is the path to the exported XDATA dds file)

Example:

cscript.exe x.vbs "c:\programdata\delorme docs\datasets\47129-m.dds" >poi.csv


Note: change q to chr(34) (eg, q=chr(34)) if you want each elemement surrounded by a quote, and change qcq to whatever delemiter you want (eg, qcq = q & "," & q for comma separated)



Dim cn, rs, sout, q, qcq, xdata
q = ""
qcq = vbtab
xdata = WScript.Arguments.Item(0)

Set cn = CreateObject("ADODB.Connection")
cn.CursorLocation = 3

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & xdata & ";Jet OLEDB:Database Password=SELECT USER;"

Set rs = CreateObject("ADODB.Recordset")

rs.Open "select q.id, q.listing, q.address, q.city, q.state, q.zip, q.phone, q.yellow_page_heading, p.geolat / -8388608.07678 as lat, p.geolon / 8388607.9284564 as lon from (select a.* from xusertable a inner join ( select min(id) as i, ucase(phone) as ph, address, zip from xusertable where score >= 97 group by ucase(phone), address, zip ) b on a.id = b.i ) q inner join point p on q.id = p.pointid", cn, 3, 4

If Not (rs.EOF And rs.BOF) Then
Do Until rs.EOF

sout = q & rs.fields("id").value & qcq & rs.fields("listing").value & qcq & rs.fields("address").value & qcq & rs.fields("city").value & qcq & rs.fields("State").value & qcq & rs.fields("zip").value & qcq & rs.fields("phone").value & qcq & rs.fields("yellow_page_heading").value & qcq & rs.fields("lat").value & qcq & rs.fields("lon").value & q

wscript.echo sout
rs.MoveNext
Loop
End If
rs.Close
cn.Close

Set rs = Nothing
Set cn = Nothing

No comments: