Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    134

    Unanswered: RIGHT(string, #), I am not getting what's expected!

    I have the following
    Code:
    	SELECT @cLastBarcode
    	SELECT @tmpCount = RIGHT(@cLastBarcode, 4)
                 SELECT @tmpCount
    SELECT @cLastBarcode returns '14001DT0010006'

    BUT

    SELECT @tmpCount returns nothing. The RIGHT(....) function does not render any results. I am expecting '0006'.

    I read that the data type must be compatible with varchar. The @cLastBarcode was declare as char(25). I have even tried casting the @cLastBarcode char string to type varchar.

    Any hints?

    Mike B

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    Find the difference:

    SET ANSI_PADDING OFF
    declare @cLastBarcode char(25),@tmpCount varchar(25)
    set @cLastBarcode='1234567890'
    SELECT @cLastBarcode
    SELECT @tmpCount = RIGHT(@cLastBarcode, 4)
    SELECT @tmpCount
    go
    SET ANSI_PADDING ON
    declare @cLastBarcode char(25),@tmpCount varchar(25)
    set @cLastBarcode='1234567890'
    SELECT @cLastBarcode
    SELECT @tmpCount = RIGHT(@cLastBarcode, 4)
    SELECT @tmpCount

  3. #3
    Join Date
    Feb 2004
    Posts
    134
    Quote Originally Posted by snail
    Find the difference:

    SET ANSI_PADDING OFF
    declare @cLastBarcode char(25),@tmpCount varchar(25)
    set @cLastBarcode='1234567890'
    SELECT @cLastBarcode
    SELECT @tmpCount = RIGHT(@cLastBarcode, 4)
    SELECT @tmpCount
    go
    SET ANSI_PADDING ON
    declare @cLastBarcode char(25),@tmpCount varchar(25)
    set @cLastBarcode='1234567890'
    SELECT @cLastBarcode
    SELECT @tmpCount = RIGHT(@cLastBarcode, 4)
    SELECT @tmpCount
    Thanks, you are right on the money!. Good eye. I fixed it by changing
    SELECT @cLastBarcode = Barcode

    TO

    SELECT @cLastBarcode = RTRIM(Barcode)

    I am not sure where I read this, maybe BOL, but it was not advisable to turn off ansi_padding.

    Thanks for your reply.

    Mike B

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •