?
Solved

How do I change the format of SQL output - Informix

Posted on 2011-10-18
4
Medium Priority
?
946 Views
Last Modified: 2012-08-13
This is a two-parter:
I have a query and I am using NVL to grab an integer but it is bringing the result back as 1.0000000000 or 2.0000000000 when it is just in the db as a 1 or a 2.

The 2nd part is I am grabbing dates as YYYY-MM-DD, I need to change the output to their preferred format of mm/dd/yyyy

Here is the query:
select i.id, e.grad_date, p.sex, a.common_app_id, i.firstname, i.lastname, i.middlename, NVL(v.score,'') as score
from id_rec i
join adm_rec a on i.id = a.id
join profile_rec p on i.id = p.id
join ed_rec e on e.id = i.id and e.prim_sch = 1
 left outer join intvwrecom_rec v on i.id = v.id and v.intvwrecom = 'INT1'
where a.plan_enr_yr = '2011'

Sample of the output I need changed:
grad_date: 2011-06-01
score: 2.0000000000000000

What I want to see:
grad_date: 06/01/2011
score: 2
0
Comment
Question by:dcrowley_01
  • 3
4 Comments
 
LVL 18

Expert Comment

by:Dave Ford
ID: 36989451

add the INTEGER function to v.score and the CHAR function to grad_date with a parameter of USA.

HTH,
DaveSlash

e.g.

select i.id,
       char(e.grad_date, usa) as grad_date,
       p.sex, 
       a.common_app_id, 
       i.firstname, 
       i.lastname, 
       i.middlename, 
       NVL(integer(v.score),'') as score
  from id_rec i 
  join adm_rec a
    on i.id = a.id 
  join profile_rec p
    on i.id = p.id
  join ed_rec e
    on e.id = i.id
   and e.prim_sch = 1
  left outer join intvwrecom_rec v
    on i.id = v.id
   and v.intvwrecom = 'INT1'
 where a.plan_enr_yr = '2011'

Open in new window

0
 

Author Comment

by:dcrowley_01
ID: 36989711
There is no USA function in my informix, but I was able to get the date part to work like this:
 TO_CHAR(e.grad_date, "%m/%d/%iY") as grad_date

But the integer part isn't working either and I can't figure that out. It says:
Error: Routine(integer) can not be resolved
0
 

Accepted Solution

by:
dcrowley_01 earned 0 total points
ID: 36994967
Answer:
select i.id, TO_CHAR(e.grad_date, "%m/%d/%iY") as grad_date, p.sex, a.common_app_id, i.firstname, i.lastname, i.middlename, TO_CHAR(NVL(v.score,''),"*") as score
from id_rec i
join adm_rec a on i.id = a.id
join profile_rec p on i.id = p.id
join ed_rec e on e.id = i.id and e.prim_sch = 1
 left outer join intvwrecom_rec v on i.id = v.id and v.intvwrecom = 'INT1'
where a.plan_enr_yr = '2011'


0
 

Author Closing Comment

by:dcrowley_01
ID: 37016602
I had to figure this out myself, but at least this gives some history if others do a search.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question