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)
You can drop your "variable" in a single row volatile table, and join to that table in your query: