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

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

Related

How to use SQL Server stored procedures in Microsoft PowerBI?

I want to generate reports from my SQL Server tables.
I have some already made stored procedures that I would like to use to generate reports from.
I haven't found a way to do so.
Only by rewriting the queries.
Thanks :)
To execute your SP in Power BI-->
1.In SQL Server right click on your SP and select Execute. Your code is executed and a new query window opens up which was responsible for execution. Copy that Query.
2.In Power BI Query Editor, select New Source-->SQL Server. After giving the server and database, in the same window click on "Advanced Options", paste the query in the "SQL Statement" that opened up.
Check "Navigate using full hierarchy" and click OK.
3.You will see data for the parameters you passed in SP only.
On Applying these changes, you will see the dataset for this in Power BI Desktop from where you can create reports.
NOTE: This works in"Import Query" option.
Hope this works for you as it did for me, Cheers!
You can use openquery. The following syntax will work with both import data and direct query methods in Power BI Desktop.
SELECT *
FROM OPENQUERY ([server name],
'EXEC dbname.dbo.spname #parametername = ''R1''');
Expand the Advanced options in the Get Data -> SQL Server dialog, and write a SQL Statement to execute your stored procedure such as:
EXEC [dbo].[usp_NameOfYourStoredProcedure]
Firstly I think its best to make the point out that Power BI isn't Reporting Services, it expects to be given existing table data or views that you then model within it's own environment before creating your dashboards.
If you can get Power BI to do the work of your stored procedures. Once you have your data model defined within Power BI it can be reused.
There is a great introduction course for this on the Power BI website:
https://powerbi.microsoft.com/en-us/guided-learning/powerbi-learning-2-1-intro-modeling-data/
"Hi,
In an Excel workbook, open the ""Power Query"" tab.
Then choose the “From Database” drop down button and select “From SQL Server Database”
Fill in the Server and Database textboxes and click OK
In the Navigator window, double-click the desired table
In the Query Editor window, click on to the column to be displayed.
Click close and select the ""Load"" button
Connect to stored procedures.
Create another power window and fill in the server and database textboxes.
In the SQL statement textbox, type “EXECUTE  Procedure_Name”
Click Close and Load button
"

Is there Microsoft SQL Mangement studio Edit procedure command

I have around 50 databases, all identical structure. Now I have to edit one procedure, so the process is a bit complex:
expand database,
expand programmability
expand stored procedures
right click on procedure
select modify
What I want to know: Is there a command that will open the modify window for a specific procedure so that my process will just be
select database
CTRL+E to execute command
When I say command I mean text in editor window, something like this
edit procedure 'my_procedure'
Maybe I misunderstand your question... but...
If you want to use SQL Server Management Studio:
Could you simply copy the ALTER statement, paste it in a new window, change the database that window is connected to, execute, change database, execute, etc.
If you want to do it faster and more repeatable, you could just save the query to a file and write a script in cmd using sqlcmd to run that script on each of your 50 databases.
http://msdn.microsoft.com/en-us/library/ms162773.aspx
I can't imagine managing 50 databases w/ the same structure and not using scripting...

How do I export a table's data into INSERT statements?

How can I export a table from a SQL Server 2000 database to a .sql file as a bunch of INSERT INTO statements?
One of the fields in the table is a Text datatype and holds HTML so doing this by hand would be rather time-consuming.
I have access to SQL Server Management Studio 2008 to access the SQL Server 2000 database.
Updating since this Q&A was at the top of the search results when I was looking for the answer.
In MSSQL 2008 R2:
Right Click on database: Tasks -> Generate Scripts...
The Generate and Publish Scripts dialog will pop up. The Intro page is worthless. Click "Next"
Choose "Select Specific database objects" and then select the Table(s) you want to get Inserts for. Click Next and the dialog will advance to the "Set Scripting Options".
Click on Advanced and you should see:
Scroll down the list of Options until you find "Types of data to script". Click on that row and choose "Data Only" from the pull-down. Click "OK". Choose your Save options and click "Next" a few times.
Note - The output also includes the following after every 100 inserts.
GO
print 'Processed 200 total records'
Check out the SSMS Tool Pack - it's a great, FREE add-on for SQL Server Management Studio which does a lot of things - among other it can generate INSERT statements from a given table.
I have been using this stored procedure for a long time: sp_generate_inserts: the 2000 version and the 2005 (and up) version.
You use it like this:
sp_generate_inserts 'thetablename'
or if you want to filter:
sp_generate_inserts 'thetablename', #from='from ... where ... order by ...'
The sp will return inserts statements as query results. Don't forget to modify setting: increase the maximum number of characters displayed in each column (tools - options - query results).
If you can use other DB management apps the quickest way would be using a tool like SqlDbx which has a built-in "Export as inserts (SQL)" function (just execute a query like SELECT * FROM Table and then use the contextual menu from the result grid).
If you need to stick to SQL Management Studio then you could use a stored procedure like this one:
http://vyaskn.tripod.com/code/generate_inserts.txt
It generates a set of results with the SQL INSERT statement for each row of the target table. Then you can exports the results to a file, or just copy them to the clipboard and paste in the query window (it works fine even with several megabytes of data).

How can I view the original SQL that created a stored procedure in SQL Server 2008?

The title pretty much says it all.
How can I view the original SQL that created a stored procedure in SQL Server 2008?
Is this possible? I've been searching online for some leads, but I'm either missing correct vernacular or I'm just looking for something that can be found by some other means.
My basic problem is that I've got a SQL Server 2008 db here with a couple hundred stored procedures and I want to see what they are doing. I need to copy one and modify it slightly and then use it.
Open up management studio and expand the database you are after. Inside of there is a programmability folder, expand that and you will see the stored procedures. Right click on one of them and select modify.
From a query window on the db you can execute sp_helptext YOURPROCEDURENAME It's a shorthand for what Martin described.
To get the definition
select object_definition(object_id('sp_help'))
Or in management studio right click the procedure and choose a scripting option.
As long as it was not encrypted sp_helptext is the stored procured you want to show the text of any stored procedure
Of course if you were storing your sps in your source control as you should be doing, you would go there and look at it and even be able to see previous versions.
For any of the answers given so far, if there was any set up done - to create a #temp table that the proc depends on, for example - that won't exist in the results because SS stores the functional code for the proc definition, not all of the SQL used in the creation. Some things you might have to infer.

How To use a stored procedure in a crystal reports 8.5?

I have to make a new report using crystal report8.5 .
I have created a stored procedure in SQL Server 2005. The stored procedure has one input parameter.
Now I wanna to know that how I can add that stored procedure and show its result in my report
while designing that report?
thank you
First go to File > Options > Database (going from memory) and make sure the checkbox for Stored Procedures is ticked. Then, when you setup your connection to SQL Server, as well as a Tables section you'll see a Stored Procedures one beneath it. Find your stored procedure in the list, add it as the data source for your report, and you'll be able to use it as a normal source.