473,574 Members | 2,260 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a SQL Server Function From Excel VBA

1 New Member
Dear Forum,

As I'm new to VBA, I was hoping you could answer a VBA / SQL Server 2005 Function question for me.

The scenario is this:

I am trying to call a SQL Server 2005 Function from within Excel (as a Function).
So basically, I want my excel user to type into a cell =MyFunction() which will call the SQL Sever 2005 Function.

I have managed to call Stored Procs etc from within Excel VBA, but functions remain a mystery to me. I just cannot seem to assign the returned value correctly.

To further explain, I have created a small sample Function in SQL Server and is posting that code below.

Thanks

Brett


Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE FUNCTION dbo.countrecordsnow (
  3. )
  4. RETURNS INT
  5. AS
  6. BEGIN
  7.  
  8. declare
  9. @v_count INT,
  10. @v_return INT
  11.  
  12. BEGIN
  13. select @v_count = COUNT(*) from dbo.ANALYST
  14.  
  15. set @v_return = @v_count
  16. return (@v_return)
  17.  
  18. end
  19.  
  20. END
  21.  
  22.  
Aug 2 '10 #1
1 3637
vb5prgrmr
305 Recognized Expert Contributor
use a recordset object to execute your stored procedure and since you have not aliased the count, you would use rs.fields(0)



Good Luck
Aug 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2390
by: Satish Chimakurthi | last post by:
Hi all, My question is surely a basic one, but somehow, I am not able to figure it out. I have a python file "satish.py" as follows: *satish.py* def main(): y()
3
2384
by: Ken | last post by:
hello, I would to know if it is possible to call an object in a function within a class. Meaning , In a class, A function X calling onto a function Y, and function Y we want one of the two calculation ( eg seconds , out of seconds and minutes) thanks , Ken
1
2144
by: kumar yogesh via .NET 247 | last post by:
Hello, I want to develop an application to transfer data from sqlserver to excel such that , when we create a workbook in excel ,then we are able to transfer data from SQL Server to excel in away that the first three columns of the table (In SQL Server)move to the First Worksheet of the workbook,the next set ofthree columns moves to the Second...
0
865
by: Todd Lu | last post by:
Hi, I have a datagrid that needs to change when the date changes in my text box. If I manually type my date in and tab(postback) , this works fine but when i call a calendar popup window using javascript I can't seem to call the server side function to change my datagrid. I am currently calling my calendar through javascript on my onclick...
13
6678
by: ukrbend | last post by:
I'm new to Javascript and to html and am trying to make the following code snippet work but it doesn't. It refuses to call the getPage() function and I always get a 404 error. I know the code is getting as far as the iframe section as other parts of the html code work correctly. But it is not executing any code within the getPage() function...
11
407
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters,...
1
1383
by: Abhishek | last post by:
Hello All I am able to call the function exported by Exe from a dll file im getting the address of the function but whille calling that function im getting access violation Error as bellow my code Function Exported by EXE void __declspec(dllexport) ExeFn() {
0
835
by: vinaykumar Maladkar | last post by:
Hi All, I m writing a program in asp.net using C#.net. I m writing a javascript. I have a bookid in javascript and i want to get information about this bookid from server. The result should be collected if javascript itself. How to do this. Thanx.
0
1517
varuns
by: varuns | last post by:
if i need to call a python function from c, i can use PyImport _Import() python-c API. Following code shows calling python function "add1" from python module "def1" int add(int x, int y) { double answer; Py_Initialize(); PyObject *modname, *mod, *mdict, *func, *arg1, *arg2, *args, *rslt; ...
8
2934
by: Yansky | last post by:
If I have the following function: function foo(){ alert('hi'); } and I don't need to pass any parameters to it, is calling it this way:
0
7741
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6491
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5637
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5328
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3763
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2257
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.