Page 1 of 1

Teradata syntax

Posted: Thu Jul 26, 2007 8:23 am
by Hope
I have to write a query in Teradata
one of my table is empty.

select count(*) as counts
,'sourcename' as src_name

from table1


if the table is empty it returns zero rows.

I want my output to give me

0 sourcename

is there any function which will force the values 0 and sourcename.I tried zeroifnull that didnt work.can any one please help me with syntax?

Posted: Thu Jul 26, 2007 9:08 am
by chulett
Don't you have a Teradata DBA or support person of some kind there you can ask? It would certainly be... quicker.

Posted: Thu Jul 26, 2007 1:41 pm
by ray.wurlod
Does Teradata allow for SELECT in the SELECT clause?

Code: Select all

SELECT (SELECT COUNT(*) FROM table) AS COUNTS, 'sourcename' FROM table;

Posted: Thu Jul 26, 2007 2:47 pm
by Hope
it does not allow

Posted: Thu Jul 26, 2007 4:36 pm
by thamark
I have tried in my env and following is working fine

SELECT COUNT(*) CNT, 'sourcename' src_name FROM table

Are you getting error (or) nothing is returned?

Posted: Fri Jul 27, 2007 12:53 pm
by throbinson
How about a UNION?

select A.* FROM (SELECT 'dummy' AS A, 0 AS B) A
UNION
select 'table', count(*) from <tablename>

will ALWAYS return at least one row. I assume you are trying to get around the annoying warning from the teradata stage?