Greetings All,
I have a ‘non-ingres’ sql script that I am converting to ingres, and it uses a function called IsNumeric( value ) which returns true if the data can be converted to numeric data
Which is ideal for my issue.
I have two fields, job_code1 varchar(4) and job_code2 also varchar(4)
The first may contain HOUR, WKS, MTHS,YEAR
And the second a multiplier
1,10,100,1000,10K – yes dammit, thats a K in the field, representing 1000’s
The script I am converting uses
CASE JobCode1
WHEN ‘WKS’ THEN
CASE
WHEN IsNumeric(job_code2) then cast(job_code2 as Integer) * 7
Else
0
... you get the picture, and I am writing this from memory (a bad one)
And I need to replicate the functionallity into an ingres script
I thought of WHEN job_code2 IS INTEGER
Perhaps to test to see if the value can be converted to an integer, but that doesn’t appear to work, and I get error on INTEGER in that line
In fact I cannot get the IS INTEGER to work at all, even when I use select (12 IS INTEGER)
Is there a way in ingres to do what I want?
PS env is Ingres 9,2SP1 on windows 32bit
Currently trying in an isql session, but when successful it will be scripted \g
TIA
Richard
/***************************\
| New Zealander, leading the world |
\***************************/
What about making a case that check to see if the last char is a: ”K”
Using the right() function
Kim Ginnerup
Hi Richard.
There are quite a few SQL predicates which are often overlooked.
The one you want is ‘IS INTEGER’, there is also ‘IS DECIMAL’ or ‘IS FLOAT’.
For example…
* select case when 9 is integer then 1 else 0 end\g
Executing . . .
┌──────┐
│col1 │
├──────┤
│ 1│
└──────┘
(1 row)
continue
* select case when 'a' is integer then 1 else 0 end\g
Executing . . .
┌──────┐
│col1 │
├──────┤
│ 0│
└──────┘
(1 row)
continue
*
Martin Bowes
Thanks Kim, that’s a thought too,
One other I had thought of was to use a view that filtered out the ‘%K%’ values so I wouldn’t have to test for them.
I will also try Martin’s syntax
Cheers
Richard
From: info-ingr...@kettleriverconsulting.com [mailto:info-ingr...@kettleriverconsulting.com] On Behalf Of Kim Ginnerup
Sent: Wednesday, 12 September 2012 6:27 p.m.
To: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] Ingres equivalent of InNumeric()
What about making a case that check to see if the last char is a: ”K”
Using the right() function
Kim Ginnerup
Fra: info-ingr...@kettleriverconsulting.com [mailto:info-ingr...@kettleriverconsulting.com] På vegne af Richard Harden
Sendt: 12. september 2012 06:39
Appreciated All !
I shall be trying all suggestions at work tomorrow
Cheers
Richard
From: Martin Bowes [mailto:martin...@ctsu.ox.ac.uk]
Sent: Wednesday, 12 September 2012 8:19 p.m.
To: Richard Harden
Subject: RE: [Info-Ingres] Ingres equivalent of InNumeric()
select job_code1, job_code2,
case job_code1 when 'wks'
then case when job_code2 is integer then integer(job_code2) * 7
else 0 end
else -1 end /* Note that this also has to be an integer or null */
from x
From: Richard Harden [mailto:richard...@orcon.net.nz]
Sent: 12 September 2012 09:02
To: Martin Bowes
Subject: RE: [Info-Ingres] Ingres equivalent of InNumeric()
Thanks Martin
I was actually trying to use the ‘IS INTEGER’, I just could not get it to work in an isql window
Something along the lines of
Case job_code2
When job_code2 IS INTEGER then cast(job_code2 as integer) * 7 else 0 end \g
May be its just me getting the syntax wrong. I’ll try again tomorrow.
Cheers
Richard
From: Martin Bowes [mailto:martin...@ctsu.ox.ac.uk]
Sent: Wednesday, 12 September 2012 7:26 p.m.
To: Ingres and related product discussion forum
From: Richard Harden [mailto:richard...@orcon.net.nz]
Thank you for all those replies / suggestions.
I now have a script that runs successfully in Ingres
Cheers
Richard.