Thursday, August 15, 2013

Lpad & Rpad in sqlserver

Lpad & Rpad in sqlserver

 
DECLARE @vstr VARCHAR(3)
SET @vstr = 'paddig'
SELECT
RIGHT(REPLICATE(' ',100) + @test ,10) AS RPAD,
LEFT(@test + REPLICATE(' ',100) ,10) AS LPAD


or

select RIGHT(REPLICATE(' ',100) + 'padstr' ,10) AS RPAD + LEFT('padstr' + REPLICATE(' ',100) ,10) AS LPAD

No comments:

Post a Comment

web stats