Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - SQL by field position - How

Reply
 
Old 08-01-2008   #1 (permalink)
Daron


 
 

SQL by field position - How

I need to get a count on a field and I need to use the field position.
How do I do this in the SQL statement?

My code:
str_grpCnt = "SELECT Fields(" & int_Column & ") as my_Group,
Count(Fields(0)) as grp_Totals " & _
"FROM [" & str_ThisFile & "] " & _
"GROUP BY Fields(" & int_Column & ")"

I cannot use a Schema.ini. I need to use the field positon because the
incoming csv text file could have a different number of fields each
time, and I need to give the user the ability to choose which field/
column to group by. Also, the incoming field will be in various
folders.

TIA

- Daron

My System SpecsSystem Spec
Old 08-02-2008   #2 (permalink)
ekkehard.horner


 
 

Re: SQL by field position - How

Daron schrieb:
Quote:

> I need to get a count on a field and I need to use the field position.
> How do I do this in the SQL statement?
>
> My code:
> str_grpCnt = "SELECT Fields(" & int_Column & ") as my_Group,
> Count(Fields(0)) as grp_Totals " & _
> "FROM [" & str_ThisFile & "] " & _
> "GROUP BY Fields(" & int_Column & ")"
>
> I cannot use a Schema.ini. I need to use the field positon because the
> incoming csv text file could have a different number of fields each
> time, and I need to give the user the ability to choose which field/
> column to group by. Also, the incoming field will be in various
> folders.
>
> TIA
>
> - Daron
(1) Use test code like this

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sFSpec : sFSpec = oFS.GetAbsolutePathName( "<YourFile>" )
Dim oTCN : Set oTCN = CreateObject( "ADODB.Connection" )
Dim sCS : sCS = Join( Array( _
"Provider=Microsoft.Jet.OLEDB.4.0" _
, "Data Source=" & oFS.GetParentFolderName( sFSpec ) _
, "Extended Properties=""text;HDR=No;""" _
), ";" )
oTCN.Open sCS
Dim sSQL : sSQL = "SELECT * FROM [" & oFS.GetFileName( sFSpec ) & "]"
Dim oRS : Set oRS = oTCN.Execute( sSQL )
Dim oFld
For Each oFld In oRS.Fields
WScript.Echo oFld.Name
Next
WScript.Echo oRS( "F1" )
oRS.Close
oTCN.Close

to verify that on your system (without schema.ini definition and with
"HDR=No") the default/automatic field names really are "F1", "F2", ...

(2) Use "SELECT F<N> ... GROUP BY F<N>" accordingly
My System SpecsSystem Spec
Old 08-02-2008   #3 (permalink)
Daron


 
 

Re: SQL by field position - How

On Aug 2, 6:22*pm, "ekkehard.horner" <ekkehard.hor...@xxxxxx> wrote:
Quote:

> Daron schrieb:
>
Quote:

> > I need to get a count on a field and I need to use the field position.
> > How do I do this in the SQL statement?
>
Quote:

> > My code:
> > str_grpCnt = "SELECT Fields(" & int_Column & ") as my_Group,
> > Count(Fields(0)) as grp_Totals " & _
> > * * * * * *"FROM [" & str_ThisFile & "] " & _
> > * * * * * *"GROUP BY Fields(" & int_Column & ")"
>
Quote:

> > I cannot use a Schema.ini. I need to use the field positon because the
> > incoming csv text file could have a different number of fields each
> > time, and I need to give the user the ability to choose which field/
> > column to group by. Also, the incoming field will be in various
> > folders.
>
Quote:

> > TIA
>
Quote:

> > - Daron
>
> (1) Use test code like this
>
> * *Dim oFS * * : Set oFS *= CreateObject( "Scripting.FileSystemObject" )
> * *Dim sFSpec *: sFSpec * = oFS.GetAbsolutePathName( "<YourFile>" )
> * *Dim oTCN * *: Set oTCN = CreateObject( "ADODB.Connection" )
> * *Dim sCS * * : sCS * * *= Join( Array( _
> * * * * * * * * * * * * * * * "Provider=Microsoft.Jet.OLEDB.4.0" _
> * * * * * * * * * * * * * * , "Data Source=" & oFS.GetParentFolderName( sFSpec ) _
> * * * * * * * * * * * * * * , "Extended Properties=""text;HDR=No;""" _
> * * * * * * * * * * * * * * * * * * * *), ";" )
> * *oTCN.Open sCS
> * *Dim sSQL * *: sSQL * * = "SELECT * FROM [" & oFS.GetFileName( sFSpec ) & "]"
> * *Dim oRS * * : Set oRS *= oTCN.Execute( sSQL )
> * *Dim oFld
> * *For Each oFld In oRS.Fields
> * * * *WScript.Echo oFld.Name
> * *Next
> * *WScript.Echo oRS( "F1" )
> * *oRS.Close
> * *oTCN.Close
>
> * * *to verify that on your system (without schema.ini definition and with
> * * *"HDR=No") the default/automatic field names really are "F1","F2", ...
>
> (2) Use "SELECT F<N> ... GROUP BY F<N>" accordingly
Thank you. I will try this on Monday when I get back.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
IE8 gets the Prime position Browsers & Mail
Get the position in a DataGridView .NET General
BCC field Vista mail
Position in an array PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46