![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | 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 |
My System Specs![]() |
![]() |
| 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 | |||