I have a query that checks if at least one row exist in the three tables A,B and C where I want to do the check that theDate=myDate. I want to be able to see if the tables contain data for a certain date (myDate). I want the variable myDate to be chosen by the user when running the query. How do I do that? FYI: I am using Teradata:
The query:
SELECT 'A' AS "Table", CASE WHEN COUNT(*) = 1 THEN 'Y' ELSE 'N' END AS "True?"
WHERE EXISTS (SELECT * FROM A WHERE theDate=myDate)
UNION ALL
SELECT 'B', CASE WHEN COUNT(*) = 1 THEN 'Y' ELSE 'N' END
WHERE EXISTS (SELECT * FROM B WHERE theDate=myDate)
UNION ALL
SELECT 'C', CASE WHEN COUNT(*) = 1 THEN 'Y' ELSE 'N' END
WHERE EXISTS (SELECT * FROM C WHERE theDate=myDate)
I think a dynamic procedure/Macro will best suite your requirement. Compile the below procedure :
After this in you call statement just put your date( as an input parameter ). The output will be the result of the select query you desire.
In case you are using a macro the below code would give you the output :
Thanks