Teradata syntax

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Hope
Participant
Posts: 97
Joined: Sun May 13, 2007 2:51 pm
Contact:

Teradata syntax

Post 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?
Last edited by Hope on Thu Jul 26, 2007 9:15 am, edited 1 time in total.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Don't you have a Teradata DBA or support person of some kind there you can ask? It would certainly be... quicker.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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;
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Hope
Participant
Posts: 97
Joined: Sun May 13, 2007 2:51 pm
Contact:

Post by Hope »

it does not allow
thamark
Premium Member
Premium Member
Posts: 43
Joined: Thu Jan 29, 2004 12:12 am
Location: US

Post 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?
Hmm i will fill this when ever i get one
throbinson
Charter Member
Charter Member
Posts: 299
Joined: Wed Nov 13, 2002 5:38 pm
Location: USA

Post 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?
Post Reply