Saturday, January 9, 2016

SQLServer - Integer Format

select id from table_name

select cast(format(row_number() over (order by id)  ,'0000#') as varchar) from table_name

Results of above two query in below picture.

I ran same query in SQLServer Version 2008, as "format" function is not available in 2008, so below is the altrenative lof same query in SQLServer 2008 version.

Msg 195, Level 15, State 10, Line 1
'format' is not a recognized built-in function name.

select RIGHT ('0000'+ CAST(row_number() over (order by id) AS varchar), 5) from tabe_name

No comments:

Post a Comment

web stats