Display stored procedure using a sql - sql-server-2008

I need to display the entire code in a stored procedure using SQL query when i have the name and db of the stored procedure

sp_helptext seems like it might do the trick for you. Syntax here.

Try this:
SELECT [definition]
FROM sys.sql_modules
WHERE object_id = OBJECT_ID('dbo.YourStoredProcNameHere')
Works in SQL Server 2005 and newer.

Related

how to convert a sql server store procedure to mysql procedure?

I have to convert store procedure from that is written in sql server, to mysql procedure. I know the their general differences like AS, GO and ; but still mysql procedure has not the same result as sql server. It is noteworthy that tables and their data are the same. can anyone say other differences between them?
I will thank you if you tell me correct answer in this case
I figure out for using mysql parameters like IN b INT in procedure code, I must use b directly! not #b like sql server

sql server stored procedures in jaspersoft studio 5.6

I have a stored procedure my_sp which takes in two parameters, first an integer and then a date. That is,
EXEC my_sp 265522,'6-10-15'
I have been trying to design a report based on the result set from this procedure in Jaspersoft Studio 5.6. The report does not generate or atleast takes way too long if I use the two parameters though the output data consists of only 25 rows. I am using this query,
exec my_sp $P{param1} , $P{param2}
and feel the probelm is with the syntax only. Also the same query works perfect when I had tried it in Sql Server Management Studio and in jaspersoft studio, stored procedures with a single parameter work like magic. Kindly help me out on this
This should absolutely work.
Add an ! after the P of each parameter
Is the SP creating temp tables? If so try another driver OR create another SP that returns the result of this SP
Try another driver anyway
add the #paramname from tsql = $P{} instead of anonymously naming them

Get stored procedure column names

I have a stored procedure looking like this:
SELECT
nTransactionId
,strInstrument
FROM dbo.Deals
I've read that for SQL Server 2012 I can use sp_describe_first_result_set, but is there any alternative for SQL Server 2008?
When I say I want the column names I mean nTransactionId and strInstrument. Even if the query doesn't return any result.
Many thanks!
For that purpose I mostly use :
SET FMTONLY ON;
Returns only metadata to the client. Can be used to test the format of
the response without actually running the query.
Have a look here: Sql Server SET FMTONLY (Transact-SQL)
This is what DataSet designer is using for example in order to get the parameteres of a procedure.

mysql DECLARE WHILE outside stored procedure how?

I fairly new to mysql but have MS SQL experience.
Is it possible to declare variables and use while statement
outside stored procedure?
I only found examples where guys doing like this
1. procedure created
2. execute proc
3. drop proc
Suggest me the right way
No, you cannot do it. You can use these statements only inside BEGIN...END clause.
So, it is possible in stored procedures/functions, triggers and events.
More information here - MySQL Compound-Statement Syntax.

View schema of resultset in SQL Server Management Studio

Is there any way in Sql Server Management Studio (2008) whereby I can view the data types of each field in the result of a query?
In this case, I am running a stored procedure which returns a result set, and I would like to know the lengths of the nvarchar columns and precision of decimals.
In the past, I have created a view which contains the underlying query in the stored procedure, and then viewed the column list, but the query within the procedure is much too complex to do so in this case.
Any ideas?
Quick and dirty snippet, requires all the fields in the result set are named or aliased;
select * into #T
from
openrowset('SQLNCLI', 'Server=.;Trusted_Connection=yes;', 'exec thedb.dbo.sp_whatever')
exec('use tempdb exec sp_columns #T drop table #T')
Your best bet may be to use OPENROWSET to store the output of the procedure into a table, then examine that table. Something like:
SELECT * INTO YourHoldingTable
FROM OPENROWSET('SQLNCLI', 'Server=YourServerName;Trusted_Connection=yes;', 'EXEC YourDatabase.YourSchema.YourProcedureName')
GO
sp_help 'YourHoldingTable'
GO
DROP TABLE 'YourHoldingTable'
GO