Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Order By anamoly

Author  Topic 

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2008-06-02 : 13:20:23
Hi,

I have a stored procedure that has a UNION and which also does an Order BY a few fields.
Select FB_PART as Part#
.....
UNION
Select PartNumber As Part#
Order By PartNumber

As you can see the first select does not have a field named PartNumber. SSMS goes ahead and compiles it no problem. But when I run this sproc from user front end it returns no result set. I check the problem by cutting out the select UNION and run it by itself at which point it notified me that Invalid column name 'PartNumber'. Why would it go ahead and compile it in SSMS as a sproc but not the select statement by itself? Is this a SSMS setting? or a problem with SQL 05?

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-02 : 13:24:00
You've not provided full query. Are you selecting data from temporary table or table variable? Also for UNION its not necessary that you should have same fields on both sides. UNION only requires the corresponding fields on both sides to be similar (same data type) not same field.
Go to Top of Page

ibeckett
Starting Member

12 Posts

Posted - 2008-06-02 : 14:24:59
You do not provide all info but try changing it like this:

Select FB_PART as Part#
.....
UNION
Select PartNumber As Part#
Order By Part#

Ian Beckett
ibeckett at gmail dot com
www.sqlblog.ibeckett.com
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2008-06-02 : 14:33:43
Thanks folks. I just went ahead and did
ORDER BY Part#
Go to Top of Page
   

- Advertisement -