SELECT
CONCAT('IF OBJECT_ID(''',ss.[name],'.',o.[name],''') IS NOT NULL DROP ',CASE type WHEN 'V' THEN 'VIEW' WHEN 'IF' THEN 'FUNCTION' WHEN 'FN' THEN 'FUNCTION' WHEN 'P' THEN 'PROCEDURE' END ,' ',ss.[name],'.',o.[name],'~GO~~'
,replace(replace(replace(sm.[definition],CHAR(13), '~'),CHAR(10), '~'),'~~','~'),'~GO~')
FROM sys.objects AS o
JOIN sys.sql_modules AS sm
ON o.object_id = sm.object_id
JOIN sys.schemas AS ss
ON o.schema_id = ss.schema_id
WHERE 1=1
AND o.type = 'V'
- This worked for me using SSMS in Azure Synapse for Scalar Functions(FN)
, Inline Functions(IF), Procedures(P), and Views(V)
- Using the query above in SSMS CNTL-D (Query Results to Grid)
- copy results to a new query.
- select a tilde character, ~ with \n (newline), CNTL-H (Replace)
- with the find/replace popup focused use "replace using REGX", ALT+E
- Replace All, ALT+A
It looks like you got your answer already but I struggled with formatting etc. in SSMS and Azure Data Studio so figured I'd share this.