How do you get a list of the input parameters for a stored procedure using metadata in SQL Server 2005? I want to do a SELECt on it and then iterate through the variable names.
+2
A:
start here
select * from information_schema.PARAMETERS
where SPECIFIC_NAME = 'YourStoredProcedureName'
order by ORDINAL_POSITION
look for parameter_name, data_type, parameter_mode
SQLMenace
2010-08-22 23:46:14
A:
Kick ass!!!!!
I was using it to generate ADO parameters for classic asp drudgery. You saved me hours!! alter PROCEDURE dbo.createParms @procname VARCHAR(200) as
SELECT 'dbCommand.Parameters.Append (dbCommand.CreateParameter("'+ parameter_name + '"' +
','
+ CASE WHEN data_type='char' THEN 'adChar'
WHEN data_type='varchar' THEN 'adVarChar'
WHEN data_type='int' THEN 'adInteger'
WHEN data_type='text' THEN 'adLongVarchar'
WHEN data_type='datetime' THEN 'adDBTimeStamp'
WHEN data_type='bit' THEN 'adBoolean'
WHEN data_type='uniqueidentifier' THEN 'adGuid'
end
+',adParamInput,'
+CASE WHEN data_type='int' THEN '0'
WHEN data_type='datetime' THEN '0'
WHEN data_type='varchar' THEN CONVERT(VARCHAR,character_maximum_length)
WHEN data_type='char' THEN CONVERT(VARCHAR,character_maximum_length)
WHEN data_type='text' THEN 'len('+replace(parameter_name,'@','')+')'
WHEN data_type='bit' THEN '0'
WHEN data_type='uniqueidentifier' THEN '0'
end
+ ','+replace(parameter_name,'@','') +'))' AS parm
from information_schema.PARAMETERS
where SPECIFIC_NAME = @procname
Caveatrob
2010-08-23 00:31:40
A:
SQL-Server native way:
select type_name(system_type_id) as type_name
, parameter_id
, name
, max_length
from sys.parameters
where object_id = object_id(N'{schema}.{name}');
vaso
2010-08-23 00:59:43