开发者

SQL Server 2005 metadata search to get stored procedure parameters

开发者 https://www.devze.com 2023-01-12 10:36 出处:网络
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 ite开发者_开发问答rate through the variable names.start her

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 ite开发者_开发问答rate through the variable names.


start here

select * from information_schema.PARAMETERS
where SPECIFIC_NAME = 'YourStoredProcedureName'
order by ORDINAL_POSITION

look for parameter_name, data_type, parameter_mode


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}');


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
0

精彩评论

暂无评论...
验证码 换一张
取 消