A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Links and Linking in Excel
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Variable SQL Statements pulling from a cell in Excel



 
 
Thread Tools Display Modes
  #1  
Old March 22nd 06, 07:55 PM posted to microsoft.public.excel.links,microsoft.public.excel.querydao,microsoft.public.excel.worksheet.functions,microsoft.public.sqlserver.connect
external usenet poster
 
Posts: n/a
Default Variable SQL Statements pulling from a cell in Excel

Yes it's definitely possible if you handle your queries with VBA. Don't know
if Excel's Data menu option to query an external database can. Actually, I
think it can't

Check out these KB articles

http://support.microsoft.com/kb/295646

http://support.microsoft.com/?scid=h...412%2fen-us%2f


"Preacher Man" wrote:

> I have a situation that I hope someone can give me a good answer to. Please
> bear with me as I try to explain my needs.
>
> My goal is to have an Excel spreadsheet that pulls from a SQL database and
> the the query pulls from a variable in the Excel sheet. For example let's
> say I am pulling Sales Orders from SQL, let's also simply assume the record
> has two fields Year and SOno.
>
> Under a simple query I could say Select * from table. Of course that would
> pull all so's from every year.
>
> To filter the query of course I could say Select * from table where
> year='2006'. And naturally that would give me 2006 orders.
>
> OK, here's where I can't figure this out. I want the query to filter
> according to a value in a cell in excel. Let's use cell A1. Essentially I
> am looking for a query that says "Select * from table where Year=(Cell A1 in
> the Sheet)"
>
> Is this possible?
>
>
>

Ads
  #2  
Old March 22nd 06, 09:57 PM posted to microsoft.public.excel.links,microsoft.public.excel.querydao,microsoft.public.excel.worksheet.functions,microsoft.public.sqlserver.connect
external usenet poster
 
Posts: n/a
Default Variable SQL Statements pulling from a cell in Excel

Thanks for the tip on the parameters. I didn't know it was there. But I
still have a problem.

The select statement I am using is just a little complex, but it is too
complex for MS Query to display graphically. So when I use the where
field=? and run the query, it comes back and says "Parameters are not
allowed in queries that can't be displayed graphically" Please tell me
there is a workaround.

Thanks.

"Duke Carey" > wrote in message
...
> Yes it's definitely possible if you handle your queries with VBA. Don't
> know
> if Excel's Data menu option to query an external database can. Actually,
> I
> think it can't
>
> Check out these KB articles
>
> http://support.microsoft.com/kb/295646
>
> http://support.microsoft.com/?scid=h...412%2fen-us%2f
>
>
> "Preacher Man" wrote:
>
>> I have a situation that I hope someone can give me a good answer to.
>> Please
>> bear with me as I try to explain my needs.
>>
>> My goal is to have an Excel spreadsheet that pulls from a SQL database
>> and
>> the the query pulls from a variable in the Excel sheet. For example
>> let's
>> say I am pulling Sales Orders from SQL, let's also simply assume the
>> record
>> has two fields Year and SOno.
>>
>> Under a simple query I could say Select * from table. Of course that
>> would
>> pull all so's from every year.
>>
>> To filter the query of course I could say Select * from table where
>> year='2006'. And naturally that would give me 2006 orders.
>>
>> OK, here's where I can't figure this out. I want the query to filter
>> according to a value in a cell in excel. Let's use cell A1. Essentially
>> I
>> am looking for a query that says "Select * from table where Year=(Cell A1
>> in
>> the Sheet)"
>>
>> Is this possible?
>>
>>
>>



  #3  
Old March 23rd 06, 09:35 AM posted to microsoft.public.excel.links,microsoft.public.excel.querydao,microsoft.public.excel.worksheet.functions,microsoft.public.sqlserver.connect
external usenet poster
 
Posts: n/a
Default Variable SQL Statements pulling from a cell in Excel

Use http://vangelder.orcon.net.nz/ QueryEditor to get around this
limitation.
BTW a table cannot be a variabl/parametere in an SQL query so you'll
need to update the SQL statement manually for each TABLE.
Using VBA would be the best. Here is some speudo code you could use
after you created the Query manually first

DIm qtb as QueryTable
DIm strTable as String
Const Query = "Select * FROM %TABLE% where year=?"

Set qtb = Activesheet.QueryTables(1)
qtb.CommandText = Query
strTable = Inputbox("Enter a table Name")
qtb.CommandText = replace(Query,"%TABLE%",strTable)
qtb.refresh

DM Unseen

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically Changing Cell Reference's when Pasting in Excel No I'm Spartacus Excel Discussion (Misc queries) 0 February 13th 06 01:01 PM
I want to use a formula in excel to highlight a cell 30 days prio MWad22368 Excel Worksheet Functions 1 February 13th 06 02:51 AM
Input cell reference is not valid (One Variable Data Table) Dottore Excel Worksheet Functions 9 September 1st 05 03:05 PM
Input Cell in One variable data table Dottore Magistrale Excel Worksheet Functions 0 August 30th 05 06:25 PM
copying cell names Al Excel Discussion (Misc queries) 12 August 11th 05 03:01 PM


All times are GMT +1. The time now is 09:59 PM.


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