LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default SQL Query from Excel

Sure, you could do that. Assuming that the data is pasted in Sheet1,
starting in A2 and below:

Sub MakeSQL()
Dim i As Long
Dim Sql As String
With Sheets("Sheet1")
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
Sql = Sql & ",'" & .Cells(i, 1).Value & "'"
Next i
Sql = Mid$(Sql, 2)
End With
Sql = "select month, sum(sales_amount) from CompanySales where
Company_Name in (" Sql & ") group by month;"
End Sub

I assumed that you have to enclose the texts within single quotes, as
usual...

--
Regards

Juan Pablo González

"Rob" wrote in message
...
I have a need for our business customers to be able to insert a list of

customers then chart their performance. The data is stored in SQL Server.
I would like for them to be able to paste a list of customers into the
spreadsheet and then use that list in my database query. There are about
8000 customers and most of the lists would have about 100 of the customers.

An example would be them pasting a list like this into Sheet 1:
company ABC
company 123
Company XYZ

I would want my query to look like this:
select month, sum(sales_amount) from CompanySales where Company_Name in

(company ABC, company 123, Company XYZ) group by month;

Then I could create an Excel chart on the returned data. Is there any way

to do this or would this have to be done with some kind of filter?

Thanks,
Rob



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 / MS Query - editing existing query to another sheet Hotpepperz Excel Discussion (Misc queries) 0 June 13th 08 06:53 PM
Can I use MS Query in Excel like an Append Query in Access Sam Wardill Excel Discussion (Misc queries) 0 April 11th 06 02:41 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 1 November 29th 05 01:44 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 0 November 28th 05 06:37 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 12:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"