Get stored procedure column names - sql-server-2008

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.

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

Display stored procedure using a sql

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.

SQL Server stored procedure for inserting multiple rows in one table and single row in other table

I am in need of a stored procedure for sales transaction. In a single SP I need to store CustomerID in one table and list of products purchased (multiple rows) in another table.
Can any one give me an best example?
Thanks in advance.
Table-Valued Parameters is a new feature introduced in SQL SERVER 2008. In earlier versions of SQL SERVER it is not possible to pass a table variable in stored procedure as a parameter, but now in SQL SERVER 2008 we can use Table-Valued Parameter to send multiple rows of data to a stored procedure or a function without creating a temporary table or passing so many parameters.
You can read about it here
for more information about using it with ado
check this great article
SQL Server 2008 Table-Valued Parameters and C# Custom Iterators: A Match Made In Heaven!
well in the stored procedure you can use any many insert commands as you want in any table you want, as your question is not clear enough that i write the exact stored procedure you want, I'm writing an example.
use [databasename]
go
create procedure [dbo].[my_stored_procedure](#customerid int) as
begin
insert into [customerstable](customerid) values (#customerid)
insert into [someothertable](somefieldname1, somefieldname2) values(somefield1value, somefield2value)
insert into [someothertable2](somefieldname1, somefieldname2) values(somefield1value, somefield2value)
end

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