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:
01640622
Views:
64
This message has been marked as the solution to the initial question of the thread.
>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.

What is the CommandText?
It should be something like:
 cmd.CommandText = "SELECT * FROM [dbo].[SP_Aankopen] (?, ?)"
 cmd.CommandType = adCmdText
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform