Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Accessing Table Function from Excel
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2014
OS:
Windows 10
Network:
Windows Server 2012 R2
Miscellaneous
Thread ID:
01640618
Message ID:
01640619
Views:
50
What do you pass as sp in your function?

Don't name your table function with sp_ prefix. First of all, it's a function, not a stored procedure and secondly, sp_ is reserved for MS stored procedures, so it's better to avoid naming user functions and procedures starting with sp_.

You can name your function fnAankopen.

What is adCmdTable type and are you sure this is what you need to use here? What are possible choices for the type?

Also, try moving setting p1 and p2 to nothing after the execute.

>I have this table function :
>
>
>SET QUOTED_IDENTIFIER ON
>GO
>CREATE FUNCTION SP_Aankopen
>(	
>	@DateFrom date,
>	@DateTo date
>)
>RETURNS TABLE 
>AS
>RETURN 
>(
>	select * from dbo.aankopen
>	where Dbo.aankopen.[DocumentDate] between @DateFrom and @DateTo
>)
>GO
>
>
>Now I'm trying to access it from VBA Excel as follows:
>
>Public Function Extract(fromDate As Date, toDate As Date, sp As String) As Recordset
>    Dim cmd As New ADODB.Command
>    cmd.ActiveConnection = conn
>    cmd.CommandText = sp
>    cmd.CommandType = adCmdTable
>    cmd.Parameters.Refresh
>    
>    Dim p1 As ADODB.Parameter
>    Set p1 = cmd.CreateParameter("@DateFrom", adDBTimeStamp)
>    p1.Value = "2016-01-16"  'sqlformatDate(fromDate)
>    cmd.Parameters.Append p1
>    Set p1 = Nothing
>    Dim p2 As ADODB.Parameter
>    Set p2 = cmd.CreateParameter("@DateTo", adDBTimeStamp)
>    p2.Value = "2017-01-15" 'sqlformatDate(toDate)
>    cmd.Parameters.Append p2
>    Set p2 = Nothing
>    Dim rs As New Recordset
>    Set rs = cmd.Execute()
>    Set Extract = rs
>    Set rs = Nothing
>End Function
>
>
>This gives error 8004014 No parameters supplied for the function 'SP_Aankopen' in the following statement :
>
> Set rs = cmd.Execute()
>
>
>In SSMS this works fine :
>
>
>USE [Exp_Plucz]
>GO
>
>SELECT * FROM [dbo].[SP_Aankopen] (
>  '2016-01-16','2017-01-15')
>GO
>
>
>What am I doing wrong? Many thanks.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform