dbaccess sql output
Posted in 1998
A while back there was a thread started by Terron Wright <twright@inbrand.com>
in which he asked:
> Is there away to force a sql dbaccess script to produce output with each
> record being displayed horizontally?
Since isql and dbaccess separate long records displayed vertically with an
empty line, you could pipe the output of the sql script into this little
sed script:
sed '
:join
/\\n$/b endline
N; b join
:endline
s/\\n/ /g
'
It joins each line to the previous line (keeps jumping back to label "join",
but jumps to label "endline" at a blank line, where the embedded newlines
are stripped out and the line prints.
In the example that follows, I've stripped out the labels in my select
statement. A problem with that is that an empty column will cause a
premature jump to "endline":
#!/usr/bin/ksh
#
# finmods
# CMcG 06/02/98
# list of tracmods recently finished
# give -o flag with comma-separated column numbers to set new order-by
# (default = program name, date-completed)
# give -t flag with number to set number of days to select (default = 14)
#
USAGE="\\n$0 - List of tracmods recently finished \\n
Usage: $0 [-o #] [-t #] \\n
-o : give comma-separated list of column numbers to set new order-by \\n
-t : give number of days to select \\n\\n"
ord_by="1,5"
days_old="14"
while getopts o:t: c
do
case $c {
o) ord_by=$OPTARG;;
t) days_old=$OPTARG;;
\\?) echo $USAGE
exit 2;;
}
done
(
cat <<EOF
output to pipe "cat" without headings
select prog_name,
completed_by,
tracmod_nbr,
status_cde,
completed_dtetime,
s_desc
from ih_tracmods_406 a
where completed_dtetime > CURRENT - $days_old UNITS DAY
ORDER BY $ord_by;EOF
) |
dbaccess tracsy - 2>/dev/null |
sed '
:join
/\\n$/b endline
N; b join
:endline
s/\\n/ /g
'
--
______________________________________________________________________
| Colin McGrath cmm@trac3000.ueci.com |
| Raytheon Engineers & Constructors, Inc. (215) 422-4144 |
| Phila, PA, USA |
| Any opinions I state are my own and not necessarily of my employer |
|____________________________________________________________________|