Skip to main content

Posts

Featured

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:
CREATEFUNCTION[dbo].Stringlinebreak(@StringNVARCHAR(1000),
@LengthINT,
@CharVARCHAR(5))
returnsNVARCHAR(max)
BEGIN
DECLARE@ReturnStringNVARCHAR(max)
DECLARE@ActualLengthINT
DECLARE@IINT

SET@ReturnString=@String

SELECT@ActualLength=Len(@String)

IF(@ActualLength>(@Length*2

Latest Posts

Fix HTML Table Header While Scrolling Page Using jQuery