If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Alias not working for filtered parameter!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-12, 14:32
avt2k6 avt2k6 is offline
Registered User
 
Join Date: Dec 2005
Posts: 42
Alias not working for filtered parameter!

Hello all,

I got an issue how to make the following query is working:

================================================== =======

SELECT SchoolInfo.Year, (SELECT StatusInfo.StatusText FROM StatusInfo WHERE StatusInfo.StatusId = SchoolInfo.StatusId ) Status
FROM SchoolInfo
WHERE SchoolInfo.Year = P_YEAR AND Status = P_STATUS;

================================================== =======
I tried to run above query with real value for Year and Status but it display the error: "Status is invalid identifier". How do I can use ALIAS to filter for parameter. Thanks in advance.

Last edited by avt2k6; 01-17-12 at 16:39. Reason: Clarification
Reply With Quote
  #2 (permalink)  
Old 01-17-12, 14:35
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,205
Please publish the exact query which you "tried to run above query with real value for Year and Status".
Reply With Quote
  #3 (permalink)  
Old 01-17-12, 15:44
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Two obvious mistakes. The first one: space between "StatusInfo" and ".StatusText" in the second line. The second one: comma behind the "Status," (the second line again).

You should consider copy/pasting of your SQL*Plus session, as it helps a lot. Don't forget to FORMAT your code and enclose it into the [code] tags to preserve formatting.
Reply With Quote
  #4 (permalink)  
Old 01-17-12, 16:46
avt2k6 avt2k6 is offline
Registered User
 
Join Date: Dec 2005
Posts: 42
I have corrected my typo. I added another filter for alias name: Status in order to filter the record by Year and Status. Originally, the query is working well if filter by Year. Here is the query with values:

SELECT SchoolInfo.Year, (SELECT StatusInfo.StatusText FROM StatusInfo WHERE StatusInfo.StatusId = SchoolInfo.StatusId ) Status
FROM SchoolInfo
WHERE SchoolInfo.Year = '2006' AND Status = 'Graduated';


The error occurred at Status is invalid identifier??? I am new with Oracle, so an idea how to change the code to make it happen. Thanks in advance.
Reply With Quote
  #5 (permalink)  
Old 01-17-12, 18:22
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
Code:
SELECT schoolinfo.YEAR,
       statusinfo.statustext
FROM   statusinfo,
       schoolinfo
WHERE  statusinfo.statusid = schoolinfo.statusid
       AND schoolinfo.YEAR = '2006'
       AND statusinfo.statustext = 'Graduated';
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #6 (permalink)  
Old 01-18-12, 11:52
avt2k6 avt2k6 is offline
Registered User
 
Join Date: Dec 2005
Posts: 42
Thanks for your detailed code. It works very well.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On