How do I? cant' select attributes [message #119315] |
Wed, 11 May 2005 15:19 |
jimmylin
Messages: 2 Registered: May 2005
|
Junior Member |
|
|
Dear SQL*LIMS Community:
Let me share a piece of code with you first,
CODE--------------
SELECT s.sample_id,
a.text_value
FROM NAIS_all_SAMPLES s, nais_sample_attributes a
WHERE
s.sample_id = 200000698 and
s.sample_id=a.sample_id and
upper(a.name) = 'COMMENTAIRE'
/
END CODE-----------
What this code does is that it grabs the 'COMMENTAIRE' value from the 'COMMENTAIRE' field in the ATTRIBUTES table and sample id of s.
For example, if, in the attribute's table, I have
text_name................text_value
COMMENTAIRE..............TOP GRADE SAMPLE
then, a.text_value = 'TOP GRADE SAMPLE'
This code works only if there is a 'COMMENTAIRE' field in the attribute section. As in case 1 and case 2,
case 1:
text_name.................text_value
COMMENTAIRE...............TOP GRADE SAMPLE
case 2:
text_name.................text_value
COMMENTAIRE...............(blank)
BUT, it does not work in case 3 and case 4 where,
case 3
text_name ................text_value
(blank)...................(blank)
case 4 (a different text name)
text_name.................text_value
OTHER NAME................OTHER VALUE
Now, if case 3 and case 4 are executed, I will get 'NO ROWS SELECTED', or a blank page, so I can't get my sample ID.
My question is, what do I do if I want to grab the 'text_value' of 'COMMENTAIRE' whether 'COMMENTAIRE' is present in the attributes.
So, the expected result in case 1 would be,
---output----
200000698 TOP GRADE SAMPLE
-------------
in case 2,
----output----
200000698
--------------
in case 3
-------output-----
(blank)
------------------
in case 4,
------output----
(blank)
---------------
Is there any PL/SQL + ORACLE + SQL*LIMS expert wanna take a stab at it?
|
|
|
Re: How do I? cant' select attributes [message #119908 is a reply to message #119315] |
Mon, 16 May 2005 11:28 |
skooman
Messages: 913 Registered: March 2005 Location: Netherlands
|
Senior Member |
|
|
Did you try the following?
SELECT NVL(a.sample_id,'-')
, NVL(a.text_value,'-')
FROM NAIS_all_SAMPLES s
, nais_sample_attributes a
WHERE
s.sample_id = 200000698
and s.sample_id=a.sample_id(+)
and upper(a.name)(+) = 'COMMENTAIRE'
|
|
|
Re: How do I? cant' select attributes [message #119909 is a reply to message #119315] |
Mon, 16 May 2005 11:31 |
skooman
Messages: 913 Registered: March 2005 Location: Netherlands
|
Senior Member |
|
|
Something like this?
SQL> select * from samples;
SAMPLE_ID SOME_DATA
---------- ----------
1
2
3
4
SQL> select * from sample_attributes
2 ;
SAMPLE_ID TEXT_NAME TEXT_VALUE
---------- --------------- -----------------
1 COMMENTAIRE TOP GRADE SAMPLE
1 other something
2 COMMENTAIRE
3
SQL> SELECT s.sample_id
2 ,a.text_value
3 FROM samples s
4 ,sample_attributes a
5 WHERE s.sample_id = a.sample_id(+)
6 and upper(a.text_name(+)) = 'COMMENTAIRE';
SAMPLE_ID TEXT_VALUE
---------- ---------------------------------------
1 TOP GRADE SAMPLE
2
3
4
|
|
|