Currently I have
Payrolltable with columnsPayroll_ID,Payroll_NamePaycodetable with columnsPaycode_ID,PayCode_Desc,Payroll_ID
The Payroll_ID column can be null in "Paycode" table, when it's null, it means All Payrolls, if it's not, then it means a specific payroll in "Payroll" table.
I would like to do things like following (This is pseudo code, just to express my intention):
SELECT
PC.Paycode_ID,
PC.PayCode_Desc + ' - All Payrolls" AS PayCode_Desc
FROM
Paycode PC
WHERE
PC.Payroll_ID = null;
UNION ALL
SELECT
PC.Paycode_ID,
PC.PayCode_Desc + PR.Payroll_Name AS PayCode_Desc
FROM
Paycode PC, Payroll PR
WHERE
PC.Payroll_ID != null AND PC.Payroll_ID == PR.Payroll_ID;
How I can achieve this in one statement(important)? Thank you so much in advance! Also please feel free to edit the topic as I'm not sure I phrase it right :)
WHERE, notWHEN.... also: you cannot compareNULLwith the usual equal or not equal operators - you can only useIS NULLorIS NOT NULLJOINsyntax in the ANSI-92 SQL Standard (more than 20 years ago) and its use is discouraged=for equality not==, but I guess it's just a typo in the last query as you got it right earlier.