Navigate
Home
ArticleWiki
Forum
Newsletter
Links
Tech News
Welcome Guest.
Username:

Password:

Remember me

Problem with query on a view created by a union
Welcome, Guest. Please login or register.
February 08, 2012, 12:20:37 PM
11513 Posts in 1262 Topics by 496 Members
Latest Member: Beerdernill
Experts Round Table Network  |  Databases  |  MS SQL Server  |  Problem with query on a view created by a union « previous next »
Pages: [1]
Author Topic: Problem with query on a view created by a union  (Read 1372 times)
Carlo

Offline Offline

Posts: 1


« on: June 27, 2006, 07:16:43 AM »

Hi,

I have a view V1 created as a plain UNION from 2 tables:

SELECT * FROM T1
UNION
SELECT * FROM T2

If I create another view V2 just filtering V1 through a WHERE clause (e.g. SELECT * FROM V1 WHERE x < y) I don't get any rows returned.
However, if I write the SELECT clause within each branch of the former UNION, I correctly get all the rows.

Is this a known bug of SQL Server 2000? If yes, is there a SP fixing it?

thx,
smiley61
Logged
Kevin3NF
Moderator
*
Offline Offline

Posts: 12


WWW
« Reply #1 on: June 27, 2006, 08:57:17 AM »

Hello Carlo/Smiley61,

Can you please post the current SP level you are on?

If possible, please also post the CREATE TABLE statements and some inserts to populate them.

Lastly, ifyou post the query that does work, that will help give a basis for comparison.

To answer the direct question, I am not aware of any issues surrounding this but will be happy to look.

Thanks,

Kevin3NF
Logged

For the love of Pete...include the version of the software you are using in your question :-)
Carlo

Offline Offline

Posts: 1


« Reply #2 on: June 27, 2006, 09:04:52 AM »

I apologize for forgetting version details.

The problem has occurred on SQL Server 2000 Standard Edition SP4 (build 8.00.2039).

Actually we have noticed something else, in the meanwhile, that may be useful.

The problem happens when the UNION is between 2 tables with a very large number of columns.
After that we have seen that at a certain point SQL Server shifts the content of the columns by 1. That means that the column labeled 56 still exists but its content is now under column 57, and so on.
Which explain why the successive query does not return any result.

thx again for helping,
Carlo
Logged
Kevin3NF
Moderator
*
Offline Offline

Posts: 12


WWW
« Reply #3 on: June 27, 2006, 09:12:07 AM »

A follow-up...

Are you actually using Select * From...or was that just for example here?

I'd love to know more about what this means:
"After that we have seen that at a certain point SQL Server shifts the content of the columns by 1. That means that the column labeled 56 still exists but its content is now under column 57, and so on"

If you have the time...

Thanks,
Kevin3NF
Logged

For the love of Pete...include the version of the software you are using in your question :-)
COBOLdinosaur
ERT.com Admin

Offline Offline

Posts: 481



WWW
« Reply #4 on: June 27, 2006, 06:09:04 PM »

I'd like to hear about that as well.  It sounds like really strange behavour.  :scratch:
Logged
NeoTeq

Offline Offline

Posts: 21


« Reply #5 on: July 16, 2006, 04:14:37 PM »

No, it's behavior that sounds familiar to me too. I've had similar problems when creating views where I did a SELECT * FROM, whether in UNION or not. So, it would be very interesting to know if the problem still exists when selecting specific columns. This method always solved the problem on my end.

I'm also on SQL Server 2000 SP 4.
Logged

Still claiming: There is no peace.
Pages: [1]
« previous next »
    Jump to: