SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Execute SQL Proc


Execute SQL Proc

Author
Message
Laura_SqlNovice
Laura_SqlNovice
SSC Veteran
SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)

Group: General Forum Members
Points: 237 Visits: 501
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
AndrewSQLDBA
AndrewSQLDBA
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1752 Visits: 3427
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
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25797 Visits: 17509
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 Modens 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)
Andy Steinke
Andy Steinke
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 664
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"...
Ed Wagner
Ed Wagner
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16409 Visits: 10050
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
Laura_SqlNovice
Laura_SqlNovice
SSC Veteran
SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)SSC Veteran (237 reputation)

Group: General Forum Members
Points: 237 Visits: 501
Is it possible using ACCESS forms or reports? Thanks guys for the help.
Ed Wagner
Ed Wagner
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16409 Visits: 10050
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
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25797 Visits: 17509
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 Modens 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)
Andrew Kernodle
Andrew Kernodle
Right there with Babe
Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)Right there with Babe (792 reputation)

Group: General Forum Members
Points: 792 Visits: 8135
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.

- :-D
andrew.kimber
andrew.kimber
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 38
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)


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search