convert bigint to nvarchar by format
-
20-02-2021 - |
質問
How can I convert bigint
to nvarchar
using the following scheme:
1
converts to0001
123
converts to0123
解決
Here a possible solution:
declare @i bigint
SET @i = 125
select right( '0000' + ltrim( str( @i ) ), 4 )
他のヒント
Slight variation of danihp
's, but using the REPLICATE
function.
DECLARE @aVar bigint
SELECT @aVar = 123;
SELECT RIGHT(REPLICATE('0', 4) + LTRIM(STR(@aVar)), 4)
Will return 0123
所属していません StackOverflow