Created
June 2, 2015 00:51
-
-
Save jbnv/7ad4a7d3cb1092c36d1e to your computer and use it in GitHub Desktop.
SQL Server query to return the code for an object by name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT [Item] | |
FROM sys.sql_modules | |
CROSS APPLY ( | |
SELECT ROW_NUMBER() OVER(ORDER BY N) AS [Ordinal], | |
SUBSTRING([definition], N, CHARINDEX(CHAR(13), [definition] + CHAR(13), N) - N) AS [Item] | |
FROM dbo.Numbers | |
WHERE N <= CONVERT(INT, LEN([definition])) | |
AND SUBSTRING(CHAR(13) + [definition], N, 1) = CHAR(13) | |
) t | |
WHERE OBJECT_NAME(object_id) = 'OBJECTNAME' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment