Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > SQL Statement in ASP.NET 2.0 page gives strange error!

Reply
Thread Tools

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

 
 
washoetech
Guest
Posts: n/a
 
      09-22-2005
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





 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      09-22-2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Problem with asp-sql statement Jack ASP General 3 01-02-2005 04:04 AM
asp and sql statement in sql server db weiwei ASP General 3 09-22-2004 04:12 PM
DBI SQL column datatype not jiving with SQL statement requirement dna Perl 1 01-18-2004 04:15 PM
Re: SQL statement working in SQL Server but not in .aspx.cs page David Browne ASP .Net 0 08-21-2003 10:43 PM
Re: SQL statement working in SQL Server but not in .aspx.cs page William \(Bill\) Vaughn ASP .Net 0 08-21-2003 10:41 PM



Advertisments