MS SQL Server Function to Insert Line Break in String
Today I came across a situation where I had to break a string coming from SQL and show it in different lines on HTML. I know it's a weird situation, but so is programming :) I googled for it but couldn't find an exact solution so I decided to write an SQL user-defined function myself. While writing a function a thought why only limit it to a line-break (<br/>) So i made it more generic. here is the function: CREATE FUNCTION [dbo] . Stringlinebreak ( @String NVARCHAR ( 1000 ) , @Length INT , @Char VARCHAR ( 5 ) ) returns NVARCHAR ( max ) BEGIN DECLARE @ReturnString NVARCHAR ( max ) DECLARE @ActualLength INT DECLARE @I INT SET @ReturnString = @String SELECT @ActualLength = Len ( @String ) IF ( @ActualLength > ( @Length * 2 ) ) BEGIN SET @I