SQL Multiple REPLACE

ALTER FUNCTION [dbo].[ReplacePattern](     @P_Pattern VARCHAR(50)) RETURNS NVARCHAR(255)AS BEGIN                         SELECT                     @P_Pattern = REPLACE(@P_Pattern,  '1', 'Sundays'),                    @P_Pattern = REPLACE(@P_Pattern,  '2', 'Mondays'),                    @P_Pattern = REPLACE(@P_Pattern,  '3', 'Tuesdays'),                    @P_Pattern = REPLACE(@P_Pattern,  '4', 'Wednesdays'),                    @P_Pattern = REPLACE(@P_Pattern,  '5', 'Thursdays'),                    @P_Pattern = REPLACE(@P_Pattern,  '6', 'Fridays'),                    @P_Pattern = REPLACE(@P_Pattern,  '7', 'Saturdays')    RETURN          @P_PatternEND

Usage:

SELECT dbo.ReplacePattern('1,2,3,4')

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *