SQL Statement in ASP.NET 2.0 page gives strange error!

Discussion in 'ASP .Net' started by washoetech, Sep 22, 2005.

  1. washoetech

    washoetech Guest

    Hello,

    I have a search box on my web app that I want to search several tables in my
    SQL 2000 DB. I have set up a full text catalog for indexing.

    The following Select statement works perfectly but only searches from 1
    table:

    SELECT * FROM edl WHERE CONTAINS (*, @query)

    This is great but it only searched one table not many tables.

    So I changed the Select statement to this:

    SELECT * FROM edl WHERE CONTAINS (*, @query) UNION SELECT * FROM autometer
    WHERE CONTAINS (*, @query)

    Now I get this error:

    Exception Details: System.Data.SqlClient.SqlException: All queries in an SQL
    statement containing a UNION operator must have an equal number of
    expressions in their target lists.

    Does anyone know what I am doing wrong? I did some research on the web and
    found that the UNION operator would add to the result set but it does not
    seem to be working.

    Thanks,

    washoetech
    washoetech, Sep 22, 2005
    #1
    1. Advertising

  2. washoetech

    Hans Kesting Guest

    washoetech wrote:
    > Hello,
    >
    > I have a search box on my web app that I want to search several
    > tables in my SQL 2000 DB. I have set up a full text catalog for
    > indexing.
    > The following Select statement works perfectly but only searches from
    > 1 table:
    >
    > SELECT * FROM edl WHERE CONTAINS (*, @query)
    >
    > This is great but it only searched one table not many tables.
    >
    > So I changed the Select statement to this:
    >
    > SELECT * FROM edl WHERE CONTAINS (*, @query) UNION SELECT * FROM
    > autometer WHERE CONTAINS (*, @query)
    >
    > Now I get this error:
    >
    > Exception Details: System.Data.SqlClient.SqlException: All queries in
    > an SQL statement containing a UNION operator must have an equal
    > number of expressions in their target lists.
    >
    > Does anyone know what I am doing wrong? I did some research on the
    > web and found that the UNION operator would add to the result set but
    > it does not seem to be working.
    >
    > Thanks,
    >
    > washoetech


    a UNION returns the result as a single table, so the columns in the queries
    *have* to contain the same columns. At least order & type *need* to be the same,
    I'm not entirly sure about the actual *name* of the column, it's possible
    that the name used in the first query is used.

    Hans Kesting
    Hans Kesting, Sep 22, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William \(Bill\) Vaughn
    Replies:
    0
    Views:
    437
    William \(Bill\) Vaughn
    Aug 21, 2003
  2. David Browne
    Replies:
    0
    Views:
    448
    David Browne
    Aug 21, 2003
  3. =?Utf-8?B?U2hlbGw=?=
    Replies:
    0
    Views:
    348
    =?Utf-8?B?U2hlbGw=?=
    Feb 15, 2006
  4. Jack
    Replies:
    3
    Views:
    98
    Bob Lehmann
    Jan 2, 2005
  5. Jack
    Replies:
    6
    Views:
    164
Loading...

Share This Page