Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Execute SQL Proc Expand / Collapse
Author
Message
Posted Tuesday, December 3, 2013 11:54 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, July 31, 2014 7:40 PM
Points: 103, Visits: 500
Hi Guys,

I need to execute sql server proc from MS Access or Excel... the proc has couple of parameters, but do not have any data comming out. Can we do that? And how we can do it so that user can enter values for parameter and execute the proc.

Thanks in advance for the help.

Laura
Post #1519346
Posted Tuesday, December 3, 2013 12:08 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, September 11, 2014 3:32 PM
Points: 977, Visits: 3,357
Cannot be done that I know of. you can use a simple web page that can do this. You can always use SQL Agent and schedule the sproc.

Andrew SQLDBA
Post #1519353
Posted Tuesday, December 3, 2013 12:08 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:13 PM
Points: 12,995, Visits: 12,414
Laura_SqlNovice (12/3/2013)
Hi Guys,

I need to execute sql server proc from MS Access or Excel... the proc has couple of parameters, but do not have any data comming out. Can we do that? And how we can do it so that user can enter values for parameter and execute the proc.

Thanks in advance for the help.

Laura


You would execute it using VBA. I would think you would use textboxes or some other form of input for the parameter values.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1519354
Posted Tuesday, December 3, 2013 12:39 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 19, 2014 2:10 PM
Points: 17, Visits: 557
http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/

I've used this technique before for some quick and dirty "reports"...
Post #1519374
Posted Tuesday, December 3, 2013 12:40 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 1:42 PM
Points: 4,040, Visits: 3,477
Sean Lange (12/3/2013)
Laura_SqlNovice (12/3/2013)
Hi Guys,

I need to execute sql server proc from MS Access or Excel... the proc has couple of parameters, but do not have any data comming out. Can we do that? And how we can do it so that user can enter values for parameter and execute the proc.

Thanks in advance for the help.

Laura


You would execute it using VBA. I would think you would use textboxes or some other form of input for the parameter values.

Agreed. You'll need to add a reference to the Microsoft ActiveX Data Objects library and then you use the ADODB.Connection data type, open your connection and fire your procedures.

As a word of caution, Excel files tend to spread through network shares, email, USB drives, etc. Be careful of the connection string you define in your Excel file. You don't want to have a server/username/password combination spread throughout the world and leave your database wide open. If it were me, I'd make the user enter their connection information into a form (and don't let them save it) and then try to connect using what they entered. This will also help you restrict who can use the Excel file to run the procedure by granting execute on that procedure to those users who are authorized to use the utility.



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1519375
Posted Tuesday, December 3, 2013 12:56 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, July 31, 2014 7:40 PM
Points: 103, Visits: 500
Is it possible using ACCESS forms or reports? Thanks guys for the help.
Post #1519383
Posted Tuesday, December 3, 2013 1:01 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 1:42 PM
Points: 4,040, Visits: 3,477
Laura_SqlNovice (12/3/2013)
Is it possible using ACCESS forms or reports? Thanks guys for the help.

Access is definitely not my forte and my knowledge is more than a little outdated on it, but can't you use ADO in the event procedures behind the form? It used to be done using DAO when the form loaded. Sorry, but it's been a long time since I've touched Access.



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1519388
Posted Tuesday, December 3, 2013 1:31 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:13 PM
Points: 12,995, Visits: 12,414
Laura_SqlNovice (12/3/2013)
Is it possible using ACCESS forms or reports? Thanks guys for the help.


Yes you can do this from a form for sure. I suspect you could just as easily have a report call a stored proc, not sure how you would get the parameter values though. I haven't used ACCESS as a "programming tool" for a LONG LONG time.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1519395
Posted Tuesday, December 3, 2013 2:06 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 1:54 PM
Points: 590, Visits: 6,749
It's quite possible to use Access to call a SQL Server procedure; you'll need to have a link to your SQL Server established in the Access file first, however. If you have one (and if not, I can provide some assistance in doing so), create a Pass-Through query; it's one of the options grouped in with the rest of the types in the Query section.

Once you make the pass-through query, just enter the call to the procedure as you would in SQL Server. So, EXEC (Database).(Schema).(Procname), and put a call to the query where it's needed, either in the VBA coding for a button or form event, and that should handle it.

My memory for the process is a bit fuzzy, since I haven't had to do this in quite awhile, so if I've slipped up somewhere, let me know and I'll try to correct things.




-
Post #1519409
Posted Wednesday, December 4, 2013 8:05 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 5:34 AM
Points: 1, Visits: 30
I've recently done this for a project I was working on, all you need is a reference adding to ActiveX Data Objects

Public Function ExecuteSP(strStoredProcedure As String) As Long
Dim objCmd As ADODB.Command
Dim lngRecords As Long

Set objCmd = New ADODB.Command
objCmd.ActiveConnection = "PROVIDER=SQLOLEDB;DRIVER={SQL Server};SERVER=" ' Complete your connection string here
objCmd.CommandType = adCmdStoredProc
objCmd.CommandText = strStoredProcedure
Call objCmd.Execute(lngRecords)

ExecuteSP = lngRecords

Set objCmd = Nothing
End Function

This is a generic function for calling SPs without parameters that may return an affected record count, parameters could be added as follows
objCmd.Parameters.Append objCmd.CreateParameter("@ParamName", adInteger, adParamInput, value:=1)

Post #1519649
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse