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 column position - How (rewording)

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


 
 

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 SpecsSystem Spec
Old 08-01-2008   #2 (permalink)
Old Pedant


 
 

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,
[snip]

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 SpecsSystem Spec
Reply

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


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