SQL Server中實(shí)現(xiàn)34進(jìn)制流水碼
? ? ? ?在設(shè)計(jì)流水碼的時(shí)候,之前用10進(jìn)制,一旦數(shù)據(jù)量過大,位數(shù)就就得很多,而且光禿禿一串?dāng)?shù)字也不美觀。后來想起車牌規(guī)則,就想將流水碼也換成類似的。由于1,0和I,O很相似,所有去掉I,O,換成34進(jìn)制。
? ? ? 設(shè)計(jì)了一張表,用來存儲(chǔ)十進(jìn)制的數(shù)字,每次調(diào)用的時(shí)候加1,在方法返回的參數(shù)中,轉(zhuǎn)為34進(jìn)制。
? ? ? ?
? ? 從網(wǎng)上參考了一些資料,然后換成現(xiàn)在的樣式。
? ? SQL?Server?中方法為:
--?34?進(jìn)制 CREATE?FUNCTION?[dbo].[int2Char](@id?bigint) RETURNS?char(4) AS BEGIN; ????DECLARE?@char_return?varchar(10)?=?'',?@v_count?int; ????WHILE?@id?>?0 ?????????SELECT ????????????@v_count?=?@id?%?34,?@id?=?@id?/?34, ????????????@char_return?=?CASE ????????????????????WHEN?@v_count?<?10?THEN?RTRIM(@v_count) WHEN?@v_count?>=10?AND?@v_count=?18?AND?@v_count<?23?THEN?CHAR(55+@v_count?+?CASE?WHEN??@v_count?>?17????THEN?1??ELSE?0?END) ????????????????????ELSE?CHAR(55+@v_count?+?CASE?WHEN??@v_count?>=?23????THEN?2??ELSE?0?END) ????????????????END?+?@char_return ????RETURN(RIGHT('0000000000'?+?@char_return,?4)) END;