CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2002
    Location
    Jordan
    Posts
    30

    TSQL return value out of range

    Declare @fromitem varchar(15), @toitem varchar(15)
    set @fromitem=10
    set @toitem=60
    select categoryid,categoryno ,@fromitem , @toitem from category
    where categoryno>=10 and categoryno<=60

    thes must return categoryno between 10 and 60
    but it return 1 and 2 and 3 and........
    Why?

    Categoryno varchar(15) becuase there is many items contains letters.
    Help Please

  2. #2
    Join Date
    May 2003
    Location
    upstate NY
    Posts
    168

    Re: TSQL return value out of range

    Originally posted by fahedksa
    Declare @fromitem varchar(15), @toitem varchar(15)
    set @fromitem=10
    set @toitem=60
    select categoryid,categoryno ,@fromitem , @toitem from category
    where categoryno>=10 and categoryno<=60

    thes must return categoryno between 10 and 60
    but it return 1 and 2 and 3 and........
    Why?

    Categoryno varchar(15) becuase there is many items contains letters.
    Help Please
    What you did was select everything where the categoryno was greater then or equal to 10 and where categoryno was less then or equal to 60

    select categoryid,categoryno ,@fromitem , @toitem from category
    where categoryno BETWEEN 10 AND 60

    Will
    --------------------------------------------
    Tell me and I will forget
    Show me and I will remember
    Teach me and I will learn

  3. #3
    Join Date
    Dec 2002
    Location
    Jordan
    Posts
    30
    i do it as you say but and works fine but when i change the numbers in where line from number to parameter its return out of range data again



    Declare @fromitem varchar(15), @toitem varchar(15)
    set @fromitem=10
    set @toitem=60
    select categoryid,categoryno ,@fromitem , @toitem from category
    where categoryno BETWEEN @fromitem AND @toitem

  4. #4
    Join Date
    May 2003
    Location
    upstate NY
    Posts
    168
    Originally posted by fahedksa
    i do it as you say but and works fine but when i change the numbers in where line from number to parameter its return out of range data again



    Declare @fromitem varchar(15), @toitem varchar(15)
    set @fromitem=10
    set @toitem=60
    select categoryid,categoryno ,@fromitem , @toitem from category
    where categoryno BETWEEN @fromitem AND @toitem
    Try trimming your string. It looks like you are using numbers so I am not sure why you have your variables set up as strings. Try this

    Declare
    @fromitem varchar(15),
    @toitem varchar(15)
    set @fromitem=10
    set @toitem=60
    select categoryid,categoryno ,@fromitem , @toitem from category
    where categoryno BETWEEN LTRIM(RTRIM(@fromitem)) AND LTRIM(RTRIM(@toitem))

    Will
    --------------------------------------------
    Tell me and I will forget
    Show me and I will remember
    Teach me and I will learn

  5. #5
    Join Date
    Dec 2002
    Location
    Jordan
    Posts
    30
    STILL SAM PEOBLEM BECUASE EX
    MB100021
    MB321344
    TR121111


    I WANT RECORDS FROM MB100021 TO MB323333

  6. #6
    Join Date
    Dec 2001
    Location
    Vile-Parle, Mumbai, India.
    Posts
    14

    Solution

    Try this one.......

    SELECT categoryid,categoryno ,@fromitem , @toitem FROM category
    WHERE CONVERT(INT,LTRIM(RTRIM(SUBSTRING(categoryno,3,15)))) >=100021
    AND CONVERT(INT,LTRIM(RTRIM(SUBSTRING(categoryno,3,15)))) <=323333
    AND SUBSTRING(categoryno,1,2) = 'MB'

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured