It seems like you are looking for how to sort these in order?
If you have a trimmed text string that is only "0-9" and prefixed with "-" when negative, then you can use the below to do a character-based sort. Numbers with fewer digits are padded, and negative numbers are translated to an inversely sorted character set. Note, you need to have a conceptual "maximum length".
DECLARE @maxlen INT = 1000
DECLARE @abc123 TABLE (NumericString VARCHAR(1000)) --e.g. "Big Integer"
INSERT INTO @abc123
SELECT '123'
UNION ALL SELECT '-123'
UNION ALL SELECT '1789'
UNION ALL SELECT '2345'
UNION ALL SELECT '-3490'
UNION ALL SELECT '-6888'
UNION ALL SELECT '-1000000'
UNION ALL SELECT '0'
SELECT aa.NumericString FROM @abc123 aa
CROSS APPLY (SELECT REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
aa.NumericString,'0','z'),'1','y'),'2','x'),'3','w'),'4','v'),'5','u'),'6','t'),'7','s'),'8','r'),'9','q') [translatedDesc]
) ss --todo: you can use TRANSLATE() here if you have the option.
CROSS APPLY (SELECT
CASE WHEN LEFT(aa.NumericString,1) = '-' THEN
CONCAT('-',
REPLICATE('z',@maxlen-LEN(aa.NumericString)-1),
REPLACE(ss.translatedDesc,'-','') ) --each character is translated to a character subset where a negative 0-9 would sort in reverse order, while SQL server sorts "ASC"
ELSE
CONCAT('_', -- a "positive" indicator that sorts higher than '-' or '0'
REPLICATE('0',@maxlen-LEN(aa.NumericString)),
aa.NumericString)
END [string2]
) uu
ORDER BY
uu.string2 COLLATE Latin1_General_BIN2 ASC
bigint. Or you can usenumeric(38,0)if you need a range larger than-2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)nvarchar(max)column? If so you could consider not doing that or usingsql_variant(will sort according to datatype rules) as well as casting.