retreive data

  • Hello,

    I am trying to write an sql statement to do the following

    I have 3 columns of data that look something like this.

    A B C

    1 100 5

    2 200 8

    3 300 9

    1 100 12

    2 200 6

    3 300 11

    1 100 19

    2 200 7

    3 300 23

    I want to write a procedure that will select column "C" from the data that the user put in for column "A' and "B". I can not figure out if I should use if statements, case, or just how to compare the data. Say the user enters 1 for column A and 235 for column B. My procedure would return multiple values. I just want the value of C that resides betwen 200 and 300 of column B. Any thoughts would be greatly appreciated.

    Michael

  • Not quite sure what you are asking for. What would the parameters for your procedure be, and what would you want to return?

  • The example you have given is not very clear...can you rephrase?

  • to piggy-back on the previous two posts

    Given your example would your procedure return

    8

    9

    6

    11

    7

    23

    Lower and upper included, excluded, partially in (excluded)

    ???

    Lots and lots of question.

    You should really provide more information for us to help you

    Frank

    http://www.insidesql.de

    Btw, there is no match on column A = 1 and B>200 and <300

    Edited by - Frank Kalis on 09/20/2003 1:24:47 PM

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Something like this should work IF your data actually supports it (as Frank says, in your data 1 always equals 100, so based on what you say you want, nothing would be returned.)

    DECLARE @ainput CHAR

    , @binput INT

    SELECT C

    FROM mytable

    WHERE

    A = @ainput

    AND (B > CAST((SUBSTRING((CAST(@binput AS CHAR(#))),1,1) + '00') AS INT)

    AND B < CAST((SUBSTRING((CAST(@binput AS CHAR(#))),1,1) + '00') AS INT) + 100)

    -SQLBill

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply