barcode128b character conversion function (Pb,sql)

Source: Internet
Author: User

PB
1 //CODE128 Barcode Basics2 //There are three versions of CODE1283 //code128a: Standard numbers and letters, controls, special characters4 //code128b: Standard numbers and letters, lowercase letters, special characters5 //code128c: [00]-[99] Number Pairs set, total 1006 //This function takes the code128b version7 //bar code consists of start bit, data bit, check bit, stop bit8 //calculation process:9 //1. Take the ASC code of each character multiplied by the sum of the character sequence number (with asc=32 as the dividing point, greater than 32 minus 32, less than 32 plus)Ten //2. Calculate the check code One //3. Combination bar code: Start bit + data bit + check digit + stop bit A intLi_asc_total =104 - intLi_asc_tmp,i - Charlc_start=Char(204)//with code128b version the Charlc_stop=Char(206) - intLi_check_digit - stringLs_check_digit -  + //1. Take the ASC code of each character multiplied by the sum of the character sequence number (with asc=32 as the dividing point, greater than 32 minus 32, less than 32 plus) -For i =1To Len (as_sourcetext) +LI_ASC_TMP = ASC (Mid (As_sourcetext,i,1)) AIf li_asc_tmp >= + Then atLi_asc_total = Li_asc_total + (li_asc_tmp- +) *I - Else -Li_asc_total = Li_asc_total + (li_asc_tmp + -) *I - End If - Next - //2. Calculate the check code inLi_check_digit = mod (li_asc_total,103) -If Li_check_digit >= theThen//Special Characters toLi_check_digit = Li_check_digit + - + Else -Li_check_digit = Li_check_digit + + theEndif *Ls_check_digit =Char(li_check_digit) $ //3. Combination bar code: Start bit + data bit + check digit + stop bitPanax NotoginsengReturn Lc_start + as_sourcetext + ls_check_digit + lc_stop
Sql
1 Create FUNCTION [dbo].[udf_getstr2code128](2  @Str NVARCHAR( $))--128B Code: ChrW (204)3  RETURNS NVARCHAR( $) 4  as5 BEGIN6  DECLARE @checkB INT 7  DECLARE @i INT,@j INT8  DECLARE @str2 NVARCHAR(2)9  SET @i=1Ten   One  SET @checkB = 1  --the code value for the start bit is 104 mod 103 =1 A                   -- -   while @i <= LEN(@Str)  -  BEGIN the   SET @str2 = SUBSTRING(@Str,@i,1) -   SET @j = ASCII(SUBSTRING(@Str,@i,1))--ASCII (@str2)--does not filter invalid characters, such as Chinese characters -   IF @j<135  -   BEGIN +    SET @j=@j- + -   END +   ELSE IF @j >=135  A   BEGIN at    SET @j=@j- - -   END -   SET @checkB = @checkB +  @i * @j -   SET @i=@i+1 -  END   -   in   -  SET @checkB = @checkB % 103   --Calculate check digit to  IF @checkB< the  and @checkB>0 --some of the data directly for 103 of the mold, the explanation is not sufficient, because some check bit more than 127, the system will "eat" off them (with the rest). +  BEGIN -   SET @checkB = @checkB +  + the  END *  ELSE IF @checkB > 94  --' font settings, the matrix is defined by 2 values. You can see the font file when you look at it. $  BEGINPanax Notoginseng   SET @checkB = @checkB +  - -  END the   +      RETURN NCHAR(204)+ @Str +  Case  when @checkB>0  Then NCHAR(@checkB)ELSE NCHAR( +)END + NCHAR(206) A      the END

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.