April 21, 2010 at 3:33 pm
Select DISTINCT ACCT.ACCTNBR||','||
CASE PERSPERSTYP.PERSTYPCD when 'EMP' then 'EMP' else null end as type||','|| PERSPHONE.AREACD||PERSPHONE.EXCHANGE||PERSPHONE.PHONENBR as CELLPHONE
FROM ACCT,PERSPERSTYP,PERSPHONE WHERE (UPPER(PERSPERSTYP.PERSTYPCD) IN ('BDM','CMC','CUST','OTC','TRST','UTMA')) AND ((ACCT.TAXRPTFORPERSNBR = PERSPERSTYP.PERSNBR)) AND ((ACCT.TAXRPTFORPERSNBR = PERSPHONE.PERSNBR(+)) AND (UPPER(PERSPHONE.PHONEUSECD(+)) = 'CELL'));
With this query, I can't seem to return results. Whenever I try to concatenace with a , after the CASE it returns the following:
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
Help! and Thanks in advance!
April 21, 2010 at 5:15 pm
Are you sure you're at the right forum?
Error message looks like some Oracle stuff...
April 21, 2010 at 5:29 pm
when you concatenate, you cannot alias the CASE statement...right at the end of your case you have this:
end as type||','||
also you have a logic hole: null concated with anything will be null, so this part is bad, as you'll get NULL results:
when 'EMP' then 'EMP' else null end
Lowell
April 22, 2010 at 7:28 am
Yes, its SQL and an error stemming from my understanding of the "Case" statement or lack thereof. Its ignoring my FROM statement because I'm using the ||','|| after the case statement, and I don't know why.
April 22, 2010 at 7:37 am
as Lutz posted, both the syntax you used and the error you posted are for Oracle only; SQL server uses the plus + operator to concatenate strings:
Here is the equivilent SQL, with Left Outer join to replace the Oracle (+) operator
Select DISTINCT
ACCT.ACCTNBR
+ ','
+ CASE PERSPERSTYP.PERSTYPCD
when 'EMP'
then 'EMP'
else null
end
+ ','
+ PERSPHONE.AREACD
+ PERSPHONE.EXCHANGE
+ PERSPHONE.PHONENBR as CELLPHONE
FROM ACCT
INNER JOIN PERSPERSTYP
ON ACCT.TAXRPTFORPERSNBR = PERSPERSTYP.PERSNBR
LEFT OUTER JOIN PERSPHONE
ON ACCT.TAXRPTFORPERSNBR = PERSPHONE.PERSNBR
WHERE (UPPER(PERSPERSTYP.PERSTYPCD)
IN ('BDM','CMC','CUST','OTC','TRST','UTMA'))
AND (UPPER(PERSPHONE.PHONEUSECD) = 'CELL');
Lowell
April 22, 2010 at 7:47 am
Lowell,
I removed the alias and it worked perfectly. On to the union now....
Thank you so much for looking at this!
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy