--drop table #tcreate table #t (spaces nvarchar(9))insert into #tselect 'me' union allselect 'you' union allselect 'allofus' union allselect 'they'update #tset spaces = right(' '+spaces, 9) from #tselect * from #t
declare @sample int set @sample = 123 select @sample select str(@sample)
CREATE TABLE #Demo(Col1 VARCHAR(9),Col2 VARCHAR(9))DECLARE @Blanks VARCHAR(9)DECLARE @Value VARCHAR(9)SET @Value = '123'SET @Blanks = ' 'INSERT INTO #DemoVALUES (RIGHT(@Blanks + @Value,9),@Value)SELECT Col1 AS 'this is what I want',LEN(Col1) AS 'Lenght to prove what I want has leading blanks',RIGHT(' ' + Col2,9) AS 'Space saving',LEN(RIGHT(' ' + Col2,9))AS 'Prove space savings has leading blanks',Col2 AS 'Recommended by Bob Hovious' FROM #DemoDROP TABLE #Demo