Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 excel cell into sql that is in Excel file

Author  Topic 

Bass
Starting Member

2 Posts

Posted - 2011-02-17 : 02:56:33
Hi! I got this sql query that successfully works and returns what I need in an Excel file.
Everything would be great if the query would return the data referring to whatever(not really whatever) I put in only one cell from the same Excel file.
Is there a easy way to do this? I got the query (that works), is a SELECT from, some inner join... etc... and the final line where something is equal to that Excel cell. Short story.
Some of the code:

use scandb
select CLC_R_Pacchetto_Dati.IdPacchetto,
bla-bla-bla
from bla-bla-bla
where IdPacchetto= 'pacchetto' (here would be the reference cell)

Thank you
Cheers

Love, Bass

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-17 : 06:28:53
You can do this via a parameterized query from excel itself using MS Query. The parameter can be set to populate from an excel cell..really easy to do.

http://office.microsoft.com/en-us/excel-help/customize-a-parameter-query-HP005199548.aspx




Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

Bass
Starting Member

2 Posts

Posted - 2011-02-20 : 02:40:51
Hi! Well, it was my 1st post on this forum and many thanks to that one reply.
I tried the parameter thing on Friday at work but no luck whatsoever.
Before my post several people at work told me that what I want was possible with the help of VBA, but none knew how to do it (not even my boss). This Excel file that I made should have saved time searching the database and compose an E-mail with the right stuff in the body and put in the TO: field the right recipients so nobody can make any mistakes when sending that e-mail.
A boss from other department has send me an older file as a reference that I might use, but because he wrote it a long time ago not even him could help me on my "quest".
But that file was more than just enough in understanding and use it as a reference with trials and error, of course. I don't know anything about VBA.
I took the time to look at the code, eliminate whatever I didn't need, add stuff, learn how to concatenate two sql strings (it was a long query and VBA would not let me add everything in one string) AND the most important stuff... HOW TO ADD THAT DAMN CELL as a reference in my query which was a pain for a first timer. A lot of "'& (not many but anyways I didn't know how to put it). In the end it makes a reference to a range rather than one cell (didn't work "I am the fault for not knowing how to request it :)"). The range is something like range(name_of_sheet!(D15:D15)) :)

If anyone is interested I can provide the code simplified, maybe someone is getting a hint, like I did. It's not about sql but VBA.

CHEERS!


Love, Bass
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-21 : 01:54:24
quote:
Originally posted by Bass

Is there a easy way to do this?




Yes and read the below paragraphs ()only if; this is what you are wanted to do "trying to get the data from your SQL database tables based on some condition(s) whose values are supplied through the Excel File's Cell(s)"?

If this is so then read books Online for OpenRowSet, OpenDataSource, linked servers ..... etc which can be used by the SQL server for reading Excel Files .. Once you get the Excel's data into SQL server's environment Similar to a Table, you will be use it for the Conditional's parameter

I hope if i have perceived your requirements correctly, then this Idea would help you.

Cheers
MIK


Go to Top of Page
   

- Advertisement -