2013-11-04 35 views

回答

0

您可以使用下面的查詢。它會檢查您是否至少有3位數字來返回拆分號碼,否則返回原樣(隨意調整它)。

declare @number as int = 1000 
select case 
    when LEN(cast(@number as varchar(100))) > 3 then SUBSTRING(cast(@number as varchar(100)), 1, 3) + '/' + SUBSTRING(cast(@number as varchar(100)), 4, LEN(cast(@number as varchar(100))) - 3) 
    else cast(@number as varchar(100)) 
end 
+0

如何使用STUFF(@Number,3,0,'/')這個? – user1030181

+0

即使更好的強硬它應該是'選擇屎(@Number,4,0,'/')' – Szymon

0

它仍然需要CASE如下:

SELECT CASE WHEN LEN (@number) > 3 THEN STUFF(@number, 4, 0, '/') ELSE CONVERT (VARCHAR, @number) END; 

否則將返回NULL與LEN(@number)< = 3 順便說一句,這是一個斜槓不是反斜槓。