Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-28-2007, 08:41 PM
=?Utf-8?B?Y3BhLW1jc2UubmV0?=
 
Posts: n/a
VLOOKUP(sorta) against SQL Server table - help!

Simplified scenario:

I have column A and column B with multiple rows of variable data in the
column A cells (i.e. account numbers). I want to return a value to the cell
in column B pulled from a single SQL Server table which depends upon the
value in the column A cell (i.e. account names).

It's essentially the same as a VLOOKUP against a SQL table rather than an
Excel range. VLOOKUP will not work, so I am looking for other solutions.

I am using Excel 2007. I am aware of the SQL.REQUEST function as a clumsy
but workable solution, but it is not supported in Excel 2007.

Anyone up to the challenge? Thanks in advance! :)
Reply With Quote
  #2 (permalink)  
Old 11-28-2007, 08:50 PM
Ross Culver
 
Posts: n/a
Re: VLOOKUP(sorta) against SQL Server table - help!

Can you use VBA?

Ross


"cpa-mcse.net" <cpamcsenet@discussions.microsoft.com> wrote in message
news:ECF0D7B5-356F-44B4-939E-5BF067842C6B@microsoft.com...
> Simplified scenario:
>
> I have column A and column B with multiple rows of variable data in the
> column A cells (i.e. account numbers). I want to return a value to the
> cell
> in column B pulled from a single SQL Server table which depends upon the
> value in the column A cell (i.e. account names).
>
> It's essentially the same as a VLOOKUP against a SQL table rather than an
> Excel range. VLOOKUP will not work, so I am looking for other solutions.
>
> I am using Excel 2007. I am aware of the SQL.REQUEST function as a clumsy
> but workable solution, but it is not supported in Excel 2007.
>
> Anyone up to the challenge? Thanks in advance! :)



Reply With Quote
  #3 (permalink)  
Old 11-28-2007, 09:04 PM
=?Utf-8?B?Y3BhLW1jc2UubmV0?=
 
Posts: n/a
Re: VLOOKUP(sorta) against SQL Server table - help!

Hello,

Unfortunately, I am not a VBA guy. I researched that option and VBA code
would require static cell references (???) which would not work for me.
Essentially, I want to be able to copy this "formula" to anyplace in the
worksheet and have it pull info from SQL based upon the value of the cell to
the left of it.

"Ross Culver" wrote:

> Can you use VBA?
>
> Ross
>
>
> "cpa-mcse.net" <cpamcsenet@discussions.microsoft.com> wrote in message
> news:ECF0D7B5-356F-44B4-939E-5BF067842C6B@microsoft.com...
> > Simplified scenario:
> >
> > I have column A and column B with multiple rows of variable data in the
> > column A cells (i.e. account numbers). I want to return a value to the
> > cell
> > in column B pulled from a single SQL Server table which depends upon the
> > value in the column A cell (i.e. account names).
> >
> > It's essentially the same as a VLOOKUP against a SQL table rather than an
> > Excel range. VLOOKUP will not work, so I am looking for other solutions.
> >
> > I am using Excel 2007. I am aware of the SQL.REQUEST function as a clumsy
> > but workable solution, but it is not supported in Excel 2007.
> >
> > Anyone up to the challenge? Thanks in advance! :)

>
>
>

Reply With Quote
  #4 (permalink)  
Old 11-28-2007, 10:03 PM
Ross Culver
 
Posts: n/a
Re: VLOOKUP(sorta) against SQL Server table - help!

You could, of course, still do this in VBA. In fact, I'm not sure you have
any other choice since there's no 'Get External Data' approach for multiple
parameters as you've described. Below is a sample of what the vba code
might look like.

Dim param 'This will be used for your column A value
Dim str As String, cnn As New ADODB.Connection, X As Integer, cnnStr As
String

cnnStr = "Data Source=SQLDatabaseServer;Initial Catalog=SQLDatabase;Persist
Security Info=True;User
ID=sa;Password=whatever;MultipleActiveResultSets=T rue;Connect Timeout=180"
X = 2 ' Assuming your first A value is in row 2
cnn.ConnectionString = cnnStr
cnn.Open

Do while Sheets("Sheet1").range("A" & x).value <> ""
Dim rst As New ADODB.Recordset
rst.ActiveConnection = cnn
rst.CursorLocation = adUseClient

param = Sheets("Sheet1").range("A" & X).value

str = "Select * from tableA where fieldA = '" & param & "'"
rst.Open str
If Not rst.EOF Then
rst.MoveFirst
Do While Not rst.EOF
Sheets("Sheet1").Range("B" & X).Value = rst.Fields.Item(1).Value
'rst.MoveNext ' Watch this! If you know there's only one value
that can be returned from SQL then there's no need to loop through the
recordset. If you want to return multiple values,
' then use another variable to set the row
to write to.
Loop
End If
rst.Close
x = x + 1
loop

cnn.Close

Make sense?

Ross
"cpa-mcse.net" <cpamcsenet@discussions.microsoft.com> wrote in message
news:BDE355BE-7A8F-4EEC-A1E0-74CD9823190B@microsoft.com...
> Hello,
>
> Unfortunately, I am not a VBA guy. I researched that option and VBA code
> would require static cell references (???) which would not work for me.
> Essentially, I want to be able to copy this "formula" to anyplace in the
> worksheet and have it pull info from SQL based upon the value of the cell
> to
> the left of it.
>
> "Ross Culver" wrote:
>
>> Can you use VBA?
>>
>> Ross
>>
>>
>> "cpa-mcse.net" <cpamcsenet@discussions.microsoft.com> wrote in message
>> news:ECF0D7B5-356F-44B4-939E-5BF067842C6B@microsoft.com...
>> > Simplified scenario:
>> >
>> > I have column A and column B with multiple rows of variable data in the
>> > column A cells (i.e. account numbers). I want to return a value to the
>> > cell
>> > in column B pulled from a single SQL Server table which depends upon
>> > the
>> > value in the column A cell (i.e. account names).
>> >
>> > It's essentially the same as a VLOOKUP against a SQL table rather than
>> > an
>> > Excel range. VLOOKUP will not work, so I am looking for other
>> > solutions.
>> >
>> > I am using Excel 2007. I am aware of the SQL.REQUEST function as a
>> > clumsy
>> > but workable solution, but it is not supported in Excel 2007.
>> >
>> > Anyone up to the challenge? Thanks in advance! :)

>>
>>
>>



Reply With Quote
  #5 (permalink)  
Old 11-29-2007, 04:41 PM
=?Utf-8?B?Y3BhLW1jc2UubmV0?=
 
Posts: n/a
Re: VLOOKUP(sorta) against SQL Server table - help!

Thanks for the code. I will try it out. I also received this VBA solution:

http://www.mrexcel.com/board2/viewto...459805#1459805

I'm not a VB guy, but hopefully I will get either (or both) to work.
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:01 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Debt Consolidation | Personal Loans | Loans | Credit Cards | Current Accounts



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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114