Friday, May 15, 2015

Get the scripted Stored Procedures As Result of DB SQL Query in SQL Server.

select Definition
from
(
SELECT SM.Object_ID o, 1 ord, SM.Definition
FROM SYS.SQL_Modules As SM INNER JOIN SYS.Objects As Obj
ON SM.Object_ID = Obj.Object_ID WHERE Obj.Type = 'P'
union all
SELECT SM.Object_ID o, 2 ord, 'GO'
FROM SYS.SQL_Modules As SM INNER JOIN SYS.Objects As Obj
ON SM.Object_ID = Obj.Object_ID WHERE Obj.Type = 'P'
) a
order by o,ord

No comments:

Post a Comment