Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default SQL Query Function

Hello all,

I am trying to create a function that returns the result of an SQL query.
The best I've come up with is to use a Query Table. I pass the function two
parameters and the query returns a single value (a count of some records).
Is there maybe an easier way?? I have a lot of values to add and they need
to change based on the parameters passed.

Any Help Would Be appreciated..
TIA
Steve

Here's my code...
------------------------------------------------------------------------------------------------------
Function RunQuery(p1,p2)

Application.Volatile

Dim ConnString As String
Dim SQLString As String
ConnString = "ODBC;DSN=;UID;PWD=;Database;"

Select Case p1
Case 1
SQLString = "SELECT Count(*) AS nCount FROM table1 WHERE name =
" & p2
Case 2
SQLString = "SELECT Count(*) AS uCount FROM table2 WHERE user =
" & p2
Case 3
SQLString = "SELECT ......."
End Select

With ActiveSheet.QueryTables.Add(Connection:=ConnString ,
Destination:=ActiveCell, Sql:=SQLString)
.Name = rep & "_" & qs
.Set value
.......
.Set value
.Refresh
End With
RunQuery = ActiveSheet.QueryTables(p2 & "_" & p1)

End Function
------------------------------------------------------------------------------------------------------


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function query Rahul Excel Programming 2 August 25th 05 05:58 PM
query about VALUE function gvm Excel Worksheet Functions 1 August 9th 05 12:58 AM
Function: New Web Query vinrouge Links and Linking in Excel 2 July 2nd 05 04:54 PM
Microsoft Query rejects "nz" function in Access Query Vaughan Excel Discussion (Misc queries) 0 May 4th 05 05:20 PM
mid function in ms query suhair Excel Discussion (Misc queries) 1 February 24th 05 04:51 PM


All times are GMT +1. The time now is 02:51 AM.

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

About Us

"It's about Microsoft Excel"