How do do a query against hardcoded row values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Sheppard

    How do do a query against hardcoded row values

    Hello there,

    I was wondering if anyone could help me do a query that has a where clause
    against hardcoded row values. IE, something like this;

    Select * from myTable where myField in (24000,24001,33 221,etc)

    I could do a pivot I suppose, but I was wondering if there is a better way.
    Thank you kindly for any ideas
    John Sheppard


  • David Portas

    #2
    Re: How do do a query against hardcoded row values

    "John Sheppard" <spam@nospam.co mwrote in message
    news:g24sbs04vo @news2.newsguy. com...
    Hello there,
    >
    I was wondering if anyone could help me do a query that has a where clause
    against hardcoded row values. IE, something like this;
    >
    Select * from myTable where myField in (24000,24001,33 221,etc)
    >
    I could do a pivot I suppose, but I was wondering if there is a better
    way.
    Thank you kindly for any ideas
    John Sheppard
    >
    Is this what you mean?

    WITH t(x) AS
    (SELECT 24000 UNION
    SELECT 24001 UNION
    SELECT 33221)
    SELECT x FROM t;

    --
    David Portas


    Comment

    • John Sheppard

      #3
      Re: How do do a query against hardcoded row values


      "David Portas" <REMOVE_BEFORE_ REPLYING_dporta s@acm.orgwrote in message
      news:7YCdncGCVo ZlrdvVnZ2dneKdn ZydnZ2d@giganew s.com...
      "John Sheppard" <spam@nospam.co mwrote in message
      news:g24sbs04vo @news2.newsguy. com...
      >Hello there,
      >>
      >I was wondering if anyone could help me do a query that has a where
      >clause against hardcoded row values. IE, something like this;
      >>
      >Select * from myTable where myField in (24000,24001,33 221,etc)
      >>
      >I could do a pivot I suppose, but I was wondering if there is a better
      >way.
      >Thank you kindly for any ideas
      >John Sheppard
      >>
      >
      Is this what you mean?
      >
      WITH t(x) AS
      (SELECT 24000 UNION
      SELECT 24001 UNION
      SELECT 33221)
      SELECT x FROM t;
      >
      --
      David Portas
      >
      >
      Hello David, yes, this is what I mean, thank you. I should have thought of
      this myself...

      Thank you, much appreciated
      John

      Comment

      Working...