I want to access the stored procedure script using C#.
I used EXEC sp_HelpText STOREDPROCNAME. This is working fine.
Is there any way to retrieve stored procedure query and the stored procedure parameter separately??
ex: I need:
delete from [dbo].[tblTransactions] where [ID] = @ID
and
@ID numeric(18,0)
separately.
How to do this?
You can get the body this way, but there isn’t a way to parse out the individual statements:
You can get its parameters by:
Note that you can’t determine without brute force parsing of the definition whether the parameters have a default value, and if they do, what the default value is. You are better equipped to do these things in C# using RegEx or other parsing methods, or PowerShell like the ParamParser project I started here.