Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Troubles doing Data Retrieval from SQL
|
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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/ |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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/ |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
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/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Data storage/retrieval | Excel Discussion (Misc queries) | |||
Data Retrieval | Excel Discussion (Misc queries) | |||
Excel Form and Data Retrieval | Excel Worksheet Functions | |||
Mass book data retrieval | Excel Discussion (Misc queries) | |||
MAC Retrieval | Excel Discussion (Misc queries) |