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.
| 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#.....UNIONSelect PartNumber As Part#Order By PartNumberAs 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. |
 |
|
|
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#.....UNIONSelect PartNumber As Part#Order By Part#Ian Beckettibeckett at gmail dot comwww.sqlblog.ibeckett.com |
 |
|
|
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# |
 |
|
|
|
|
|