select top 1 cast(value as numeric) * cast(period as numeric) as "total" from test_table;
The above query will produce: 1234
However the column datatype is char(8), which is what I need, so I want all remaining space filled with preceeding zeros so the output should read 00001234.
How is this possible in T-SQL?
Answer by Madhivanan ·
1 Convert to numeric without precision makes no sense. Use int or bigint 2 If you want to show the data in front end application, do formation there 3 If you dont have any option, another method is
select replace(str(cast(1234 as int) * cast(1 as int),8),' ','0') PadNum