I’m using SQL Server. I’ve 3 tables :
- tblUser
- tblAudit
- tblEnum
The tblAudit has got 4 columns :
nUserId, nID: These two columns point to the tblUser
vFromValue, vToValue: These two columns point to the tblEnum
Now, I need to show the actual values from the tblUser and tblEnum based on the IDs present in the tblAudit table.
The query that I have written looks something like this :
SELECT A.aEventID,
U.tName AS MakerChecker,
U2.tName AS OnUser,
VLE.tDisplayName AS FromValue,
VLE2.tDisplayName AS ToValue,
A.dChangeTime AS Timestamp
FROM tblAudit A INNER JOIN tblUser U ON A.nUserId = U.aUserId
INNER JOIN tblUser U2 ON A.nID = U2.aUserId
INNER JOIN tblEnum VLE ON A.vFromValue = VLE.nIndex OR (A.vFromValue IS NULL)
INNER JOIN tblEnum VLE2 ON A.vToValue = VLE2.nIndex OR (A.vToValue IS NULL)
Because the values in the Audit table is null for the columns vFromValue and vToValue for some rows, those values are not coming as NULL but the previous value.
How can I display the null values intact by changing the above query? Please help.
Since the
tblAudit.vFromValueandtblAudit.vToValuehaveNULLs, try this:or this: