Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pull random records from Excel and Create a new sheet

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,978
US
I posted this in the vbscript forum as I was using vbscript to do most of the processing but it is truly an SQL query issue I am havning. I want to transer 10 random records from an Excel file and place them in another Excel file without using Excel Automation. This would be my query to reture 10 random records:

Code:
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & FolderPath & objFile.Name & ";" & _
"Extended Properties=""Excel 8.0;"""
"SELECT TOP 10 * FROM [Sheet1$] ORDER BY RND([COUNT])"

I am unsure of the syntax and I am not too fluent is SQL.
Code:
SELECT * INTO [Excel 8.0;Database=C:\Test2.xls].[Sheet1] WHERE (SELECT TOP 10 * FROM [Sheet1$] ORDER BY RND([COUNT]))

Swi
 
Nevermind. This seems to work.

Code:
       conn.execute "SELECT TOP 10 * INTO [Excel 8.0;Database=C:\Test2.xls].[Sheet1] FROM [Sheet1$] ORDER BY RND([ZIP4])"

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top