Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sending Params from Excel to SQL Procedure

Author  Topic 

rjackman1959
Yak Posting Veteran

60 Posts

Posted - 2009-01-13 : 20:25:35
OK I’m pretty new to SQL and I am trying to call a stored procedure from Exec passing 2 params. I don’t have a problem with 1, but I’m not sure how to send 2. I am getting an “Unclosed quotation mark after the character string” error. Any help would be appreciated. Thanks in advance

Sub Get_Settlements()
Dim command As String
Dim parm1 As String
parm1 = Range("F5").Value
Dim parm2 As String
parm2 = Range("F6").Value
' Create a connection object.
Set SuiteConn = New ADODB.Connection
' Provide the connection string.
Dim strConn As String
'Use the SQL Server OLE DB Provider.
strConn = "PROVIDER=SQLOLEDB;"
'Connect to the database on remote server.
strConn = strConn & "Data Source=IP; Initial Catalog=DATABASE;"
'Use an integrated login.
strConn = strConn & " INTEGRATED SECURITY=sspi;"
'Now open the connection.
SuiteConn.Open strConn
' Create a recordset object.
Dim rsCas As ADODB.Recordset
Set rsCas = New ADODB.Recordset
'MsgBox parm
With rsCas
' Assign the Connection object.
.ActiveConnection = SuiteConn
' Extract the required records.
.Open "wynne_get_settlements '" & parm1 & ", " & parm2
' Copy the records into cell A11 on Sheet1.
Sheet1.Range("A11").CopyFromRecordset rsCas
.Close
End With
SuiteConn.Close
Set rsCas = Nothing
Set RSuiteConn = Nothing
End Sub

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-13 : 22:45:53
quote:
Originally posted by rjackman1959

OK I’m pretty new to SQL and I am trying to call a stored procedure from Exec passing 2 params. I don’t have a problem with 1, but I’m not sure how to send 2. I am getting an “Unclosed quotation mark after the character string” error. Any help would be appreciated. Thanks in advance

Sub Get_Settlements()
Dim command As String
Dim parm1 As String
parm1 = Range("F5").Value
Dim parm2 As String
parm2 = Range("F6").Value
' Create a connection object.
Set SuiteConn = New ADODB.Connection
' Provide the connection string.
Dim strConn As String
'Use the SQL Server OLE DB Provider.
strConn = "PROVIDER=SQLOLEDB;"
'Connect to the database on remote server.
strConn = strConn & "Data Source=IP; Initial Catalog=DATABASE;"
'Use an integrated login.
strConn = strConn & " INTEGRATED SECURITY=sspi;"
'Now open the connection.
SuiteConn.Open strConn
' Create a recordset object.
Dim rsCas As ADODB.Recordset
Set rsCas = New ADODB.Recordset
'MsgBox parm
With rsCas
' Assign the Connection object.
.ActiveConnection = SuiteConn
' Extract the required records.
.Open "wynne_get_settlements '" & parm1 & "', " & parm2
' Copy the records into cell A11 on Sheet1.
Sheet1.Range("A11").CopyFromRecordset rsCas
.Close
End With
SuiteConn.Close
Set rsCas = Nothing
Set RSuiteConn = Nothing
End Sub



missed a '
Go to Top of Page

rjackman1959
Yak Posting Veteran

60 Posts

Posted - 2009-01-14 : 07:41:40
Thanks Visakh

Can you show me where it goes please?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-14 : 08:18:17
i've modified it in reply see below

.Open "wynne_get_settlements '" & parm1 & "', " & parm2

Go to Top of Page

rjackman1959
Yak Posting Veteran

60 Posts

Posted - 2009-01-14 : 10:55:37
Thank You very much this will help. I was just putting into 1 parm and then splitting it up in SQL, but this is much cleaner
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-14 : 11:57:46
cheers
Go to Top of Page
   

- Advertisement -