Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reate table and insert data into Teradata database from MS SQL Server

Status
Not open for further replies.

Mindgamez

Programmer
Sep 2, 2009
2
US
Hi,

I noticed that I can’t do sub queries in Teradata.

For example:
Select patient_name
Patient_age,
Patient_weight,
(Select Count(*) from drug_taken WHERE drug_name=”Warfarin” patient_id=10) CountWarfarin,
(Select Count(*) from drug_taken WHERE drug_name=”Heprin” patient_id=10) CountHeprin
FROM patient
WHERE patient_id=10

So what is the workaround for this? Where I don’t have to create a stored procedure.

Thank you,
-Tesh
 
Why don't you use JOIN clause.
This is Teradata, not O**e or My***. JOIN is efficient !

Code:
SELECT  ptn.patient_name
    ,   ptn.Patient_age
    ,   ptn.Patient_weight
    ,   SUM(CASE WHEN drug_name = "Warfarin" THEN 1 ELSE 0 END)  AS CountWarfarin
    ,   SUM(CASE WHEN drug_name = "Heprin" THEN 1 ELSE 0 END)  AS CountHeprin
FROM    patient     AS ptn
    LEFT JOIN
        drug_taken  AS drg
        ON  ptn.patient_id = drg.patient_id
        AND drg.drug_name IN ("Heprin", "Warfarin")
WHERE   ptn.patient_id = 10
;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top