![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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 column position - How (rewording) I need to get a count on a field and I need to use the column 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 column 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 file will be in a different folders each time. (I'm using drag-n-drop) TIA - Daron |
My System Specs![]() |
| | #2 (permalink) |
| | RE: SQL by column position - How (rewording) "Daron" wrote: Quote: > > I need to get a count on a field and I need to use the column position. > How do I do this in the SQL statement? > > My code: > str_grpCnt = "SELECT Fields(" & int_Column & ") as my_Group, You can't. But... Since you appear to be using ASP (or is it ASP.NET), you could do it in two steps. First, get a list of all the fields, in the form of a "dummy" recordset. Then get the field name from that and plug it into your second query. Example: <% sql1 = "SELECT * FROM [" & str_ThisFile & "] WHERE 1=0" Set rs1 = conn.Execute( sql1 ) fieldName = rs1.Fields(int_column).Name sql2 = "SELECT [" & fieldName & "] AS myGroup, COUNT(*) AS myCount " _ & " FROM [" & str_ThisFile & "] " _ & " GROUP BY [" & fieldName & "]" _ & " ORDER BY 1" Set rs2 = conn.Execute( sql2 ) .... %> Hmmm?? |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| IE8 gets the Prime position | Browsers & Mail | |||
| Is it possible in "computer" to view files from top to bottom in 1st column then same again in next column to the right etc? | Vista file management | |||
| Get the position in a DataGridView | .NET General | |||
| Position in an array | PowerShell | |||