MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Position and substring query Problem\Question

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
cappertan
Beginner


Joined: 20 May 2003
Posts: 15
Topics: 10

PostPosted: Thu Jan 31, 2008 12:30 pm    Post subject: Position and substring query Problem\Question Reply with quote

Hi:

The following query below works but I am stuck as how to get the final results, if possible. If I have found 'LEFT VENTRICLE' then I want to get the percentage '40-45%'. I need to have the percentage as a column by itself. Percentage could be '40% (individual number).
I am confused. Question

I have checked other sources but manuals to not give many example of combination examples. I am using this on Teradata DBMS but I would think the SQL would work on DB2 as well.

Thanks
Capp
Code:

SELECT line,
SUBSTRING (an.note_text from position('LEFT VENTRICLE' in an.note_text) for 14) as "LV",
SUBSTRING (an.note_text from position('Estimated ejection fraction is ' in an.note_text) for 37) as "EEF"
from ambulatory_notes an
where an.note_csn_id = 'XXXXX'
and (LV like '%LEFT VENTRICLE%' or EEF like '%Estimated ejection fraction is %')
    order by line

VARCHAR Data Text 1 line=254 varchar
1 LEFT VENTRICLE: Normal in size. Diastolic internal dimension is 5.2 cm.
2 Estimated ejection fraction is 40-45%. Age
3 appropriate mitral inflow pattern, tissue doppler suggests borderline
4 elevated left atrial pressures.
_________________
Capp
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Jan 31, 2008 1:07 pm    Post subject: Reply with quote

I am assuming that your output from the query is as follows

Code:

line                 LV                  Eff
=====            =============      =============
linedata xxxx    LEFT VENTRICLE
linedata yyyy                       Estimated ejection fraction


Do you want something like this ? when you found left ventricle then you want a percentage next it?

Code:

line                 LV          %        Eff                         %
=====            =============  ===   =============                  ===
linedata xxxx    LEFT VENTRICLE  40                                   0
linedata yyyy                     0   Estimated ejection fraction    58


If that is not what you wanted then show as sample like I showed
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cappertan
Beginner


Joined: 20 May 2003
Posts: 15
Topics: 10

PostPosted: Thu Jan 31, 2008 2:52 pm    Post subject: Reply with quote

Kolusu:

Yes. Your output sample is correct. That is what I want.

Thanks for quick reponse to my post.

Capp
_________________
Capp
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Jan 31, 2008 3:45 pm    Post subject: Reply with quote

cappertan,

Try this

Code:


SELECT line,
SUBSTRING (an.note_text from position('LEFT VENTRICLE' in an.note_text) for 14) as "LV",
CASE SUBSTRING (an.note_text from position('LEFT VENTRICLE' in an.note_text) for 14)
        WHEN 'LEFT VENTRICLE' THEN CHAR('40%')         
        ELSE CHAR('00%') END AS LV_PERCENT
SUBSTRING (an.note_text from position('Estimated ejection fraction is ' in an.note_text) for 37) as "EEF"
CASE SUBSTRING (an.note_text from position('LEFT VENTRICLE' in an.note_text) for 14)
        WHEN 'Estimated ejection fraction is ' THEN CHAR('58%')         
        ELSE CHAR('00%') END AS LV_PERCENT
from ambulatory_notes an
where an.note_csn_id = 'XXXXX'
  and (LV like '%LEFT VENTRICLE%' or
      EEF like '%Estimated ejection fraction is %')
    order by line
;

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group