ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Troubles doing Data Retrieval from SQL (https://www.excelbanter.com/excel-programming/293928-re-troubles-doing-data-retrieval-sql.html)

Sauron[_10_]

Troubles doing Data Retrieval from SQL
 
Cheers for the response!

Sorry I should have been more descriptive, it's the first part I'
having the trouble with, the bit where it uses cell input and joins i
all together in a query. I've tried and tried but it doesen't seem t
work properly!?!

Thanks!
Sa

--
Message posted from http://www.ExcelForum.com


Sauron[_11_]

Troubles doing Data Retrieval from SQL
 
Is there an easier way of doing dynamically built SQL queries? I can'
think of another way, would anyone be able to suggest anything?

Cheers,
Sa

--
Message posted from http://www.ExcelForum.com


Sauron[_12_]

Troubles doing Data Retrieval from SQL
 
Anyone have any ideas on this?

Cheers,
Sa

--
Message posted from http://www.ExcelForum.com


Stevie_mac

Troubles doing Data Retrieval from SQL
 
You really need to be more specific

I mean like, I've done this in the past...

Build a SQL select Query from Items on Sheet1
Output results of Query to Sheet2

Dim s as String, f as Field, r as long, c as long
s = "SELECT " & Sheet1.Cells(1,1).Value & " FROM " & Sheet1.Cells(2,1).Value & " WHERE " & Sheet1.Cells(3,1).Value
Set rs = cn.Execute(s)
while Not rs.EOF
for each f in rs
Sheets2.Cell(r,c).Value = f.Value
c = c + 1
next
rs.MoveNext
r = r + 1
wend

NOTE: this example has no error handling & is not realy good practice (since Sheet1 might not exist!) but it should get
you started!

If this is not what you need, give a bit more detail - someone will show you the way!

Stevie_Mac...

See ya.

"Sauron " wrote in message ...
Anyone have any ideas on this?

Cheers,
Sau


---
Message posted from http://www.ExcelForum.com/




Stevie_mac

Troubles doing Data Retrieval from SQL
 
Man - thats no good! out clubbing last night! - Try this instead :)
(note to self: Check before posting)


Sub test()
Dim db As Database, rs As Recordset
Set db = Workspaces(0).OpenDatabase("C:\A_DataBase.mdb")
Dim s As String, f As Field, r As Long, c As Long
s = "SELECT " & Sheet1.Cells(1, 1).Value & " FROM " & Sheet1.Cells(2, 1).Value & " WHERE " & Sheet1.Cells(3,
1).Value
Set rs = db.OpenRecordset(s)
r = 1 ' <-- important!
While Not rs.EOF
c = 1 ' <-- important!
For Each f In rs.Fields
Sheet2.Cells(r, c).Value = f.Value
c = c + 1
Next
rs.MoveNext
r = r + 1
Wend
End Sub



"Stevie_mac" wrote in message ...
You really need to be more specific

I mean like, I've done this in the past...

Build a SQL select Query from Items on Sheet1
Output results of Query to Sheet2

Dim s as String, f as Field, r as long, c as long
s = "SELECT " & Sheet1.Cells(1,1).Value & " FROM " & Sheet1.Cells(2,1).Value & " WHERE " & Sheet1.Cells(3,1).Value
Set rs = cn.Execute(s)
while Not rs.EOF
for each f in rs
Sheets2.Cell(r,c).Value = f.Value
c = c + 1
next
rs.MoveNext
r = r + 1
wend

NOTE: this example has no error handling & is not realy good practice (since Sheet1 might not exist!) but it should

get
you started!

If this is not what you need, give a bit more detail - someone will show you the way!

Stevie_Mac...

See ya.

"Sauron " wrote in message ...
Anyone have any ideas on this?

Cheers,
Sau


---
Message posted from http://www.ExcelForum.com/






Sauron[_13_]

Troubles doing Data Retrieval from SQL
 
Cheers man, really grateful!

The only problem is that other cells can be chosen instead that's why
broke it down into a series of IF statements because it wouldn't wor
if I used a static query, it needs to build based on which cells ar
typed into. Hope that's enough info!

Cheers Very Much!
Sa

--
Message posted from http://www.ExcelForum.com


onedaywhen

Troubles doing Data Retrieval from SQL
 
The usual approach is to use static SQL in a stored procedure on the
server side and get the client to pass parameter values.

--

Sauron wrote in message ...
Cheers man, really grateful!

The only problem is that other cells can be chosen instead that's why I
broke it down into a series of IF statements because it wouldn't work
if I used a static query, it needs to build based on which cells are
typed into. Hope that's enough info!

Cheers Very Much!
Sau


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 07:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com