SQL Server 2005 install stored procedure - sql-server-2005

I'm trying to install the stored procedure WhoIsActive, but have no clue where to put it.
I thought it was supposed to go in the Bin folder but I believe it's only for DLLs. How do you install a stored procedure in SQL Server 2005?
I would like to call it using
Exec dbo.sp_WhoIsActive
since it has some parameters that I can use with it

How do you install a SP in SQL 2005?
You usually execute it within the query window.
That would invovle opening the stored procedure file (.sql) or copy / pasting it in, then pressing execute (or F5).
You might want to take a look at this article, and scripting stored procedures.

Related

SSIS SQL Executation Task error: unable to run some sql queries

I'm working to make some fact tables (taking some data from some resources, doing some transformations and putting them in a table). My main dilemma is that I can't run any SQL query other than select, update, and insertion. As soon as i try:
exec someProcedure
or a conditional statement (if #part1 ...) or even (create table ...) I take errors. Opening the task to build my SQL statements and find problems it gives errors ranging from (The Set SQL construct or statement is not supported.) to (The EXEC SQL construct or statement is not supported.).
I looked for numerous topics here on stackoverflow but none were actually addressing me problem.
Thanks,
You can see a view of what I'm facing in this picture :
I expect to run my SQL commands as usual in SSIS.
Try changing the SQL Source Type from Direct Input to Stored Procedure and just specify the stored procedure name instead of Exec stored procedure
Also make sure that you have selected the relevant TargetServerVersion from the project configuration:
How to change TargetServerVersion of my SSIS Project
Based on your comments, you are using SQL Server 2012 with Visual Studio 2010 which are not compatible.
You have to use Visual Studio 2012 or 2015+ (backward compatibility added). You can refer to the SSIS tag wiki for more info:
https://stackoverflow.com/tags/ssis/info

SQL Azure: sp_helptext gives non-runnable source code

When trying to automate reading out constraint information using sp_helpconstraint I got the bright idea of pulling out the source code of the built-in SP directly and run it myself (since it returns multiple result sets so those can't be stored in a temp table). So I ran exec sp_helptext 'sp_helpconstraint' (on SQL Azure) to generate the source code, and copied it into a new query window.
However, when I run the SP (on SQL Azure), I get lot's of error messages -- for example, that object syscomments doesn't exist even though I am using the exact same source that runs perfectly when calling sp_helpconstraint directly. Just to make sure it wasn't an anomaly with the procedure or a mistake in my copy/paste execution, I tested the exact same procedure on SQL Server 2008, and if I directly copy the SP source into a new query window, it runs perfectly (obviously after removing the return statements and manually setting the input parameters).
What gives?? Do built-in SP's run in a special context where more commands are available than normal on SQL Azure version? Is sp_helptext not returning the actual source that is being run on SQL Azure?
If you want me to try anything out, give a suggestion and I can try it on our SQL Azure Development instance. Thanks!

Save output of a SP to a file and create a job to execute it

I have a SP which returns a XML string as output. I want to save the result in a .xml file automatically when the SP is executed. whats the best way to do that?
First, saving output to file:
exec xp_cmdshell 'bcp "select * from suppliers" queryout "c:\suppliers.txt" -S server -T'
Second, Scheduling a SQL Job
http://msdn.microsoft.com/en-us/library/ms190268.aspx
Alternatively (in case of SQL Express)
Use command-line SQL to execute the stored procedure from a windows task, scheduled accordingly
Build a quick .NET application that executes the stored procedure. Then, setup a windows task to run the executable on a schedule.
This might be exactly what you are looking for: http://munishbansal.wordpress.com/2009/02/20/saving-results-of-a-stored-procedure-into-a-xml-file/
In a nutshell, you have four options:
Using CLR Stored Procedure.
Using Command Line Utility (OSQL).
Using xp_CmdShell utility of SQL Server.
Creating OLE objects in SQL Server (sp_OACreate).
I will not paste most of that article here, but it is pretty well written.

SQL delphi ado, SQL batch execute

Since SQL Server does not have a simple batch command line executor for the scripts the are auto generated from management studio, I created one.
The problem arises when delphi ado syntax and SQL Server syntax don't agree (BUT ITS THE SAME THING).
Well any how, the go I replaced with ;
Now as I declare a stored procedure alter, I hit a brick wall.
The script I'm running is :
ALTER Procedure [dbo].[procName]
as
Declare #param int
and the error i get is :
the arguments are from the wrong type,
out of range or collide with one
another.
(my free translation)
questions :
why is this happening?
what can i do to change this?
is there another udl based program that parse SQL scripts?
thanks.
edit: require login to the db with udl file.
could it be that delphi has problems with # ?
Since SQL Server does not have a
simple batch command line executer for
the scripts the are auto generated
from management studio, I created one.
Are you aware of SQLCMD ?? Seems like a command-line utility to execute SQL scripts to me... also: the SQLCMD utility has a number of additional enhancements that go beyond what the T-SQL scripts in SSMS can do.
Also check out:
SQLCMD reference
Using SQLCMD utility
Not sure about your SQL example above, but does the stored procedure actually have any parameters, or are you calling a variable inside the body #param? The usual syntax is:
ALTER Procedure [dbo].[procName]
(<#params here>)
AS
<body + variables here>
MSDN - Alter Procedure
removed the component and change the code from
ado.open;
to
ado.execute;//or something like this
solved it.

From a Query Window, can a Stored Procedure be opened into another Query Window?

Is there command inside a Query Window that will open a stored procedure in another Query Window?
i.e.
MODIFY dbo.pCreateGarnishmentForEmployee
I am using SQL Server management Studio 2005 and Red Gate's SQL Prompt.
Currently I have to do the follwowing multiple steps:
Open Object Explorer
Navigate Programmability | Stored Procedure
Right Click the Stored Procedure name
Select Modify
A Query Window will open up with the ALTER PROCEDURE.
As I mentioned above, what I would like to do is from a Query Window type
in something to the effect of
MODIFY dbo.pCreateGarnishmentForEmployee
You are trying to mix two technologies here.
SQL and SQLSyntax
The SQL Management Tool
It is probably not possible to use TSQL to manipulate the Management Studio, which is what you appear to want. I suspect cut and paste is your only option.
I think that the only way that I'm aware of that produces an outcome similar to what you're asking for is running sp_helptext against your stored procedure name
sp_helptext 'dbo.pCreateGarnishmentForEmployee'
which will output the text as a resultset. Then click on the column header and copy/paste the resultset into the query window. You'll also need to change the
CREATE PROCEDURE ...
to
ALTER PROCEDURE ...
This method does not always produce the nicely formatted layout of your stored procedure however, so bear this in mind.
There is a way to do this from the command line (i.e., from outside of SSMS).
It requires that you save your stored procedure text (as in, click "save", not execute). Here's an example:
Ssms "C:\...\SQL Server Management Studio Projects\mySolution\myProject\myScript.sql"
See the article on MSDN for more detailed info: http://msdn.microsoft.com/en-us/library/ms162825.aspx