Imagine I have a table with integer columns Col1, Col2, Col3, Col4. Each column is NULL, and a valid row must contain a value in exactly 1 column (i.e., all NULL values are invalid and more than 1 column is also invalid).
I currently have a control limit like this
ALTER TABLE [dbo].[MyTable] WITH CHECK
ADD CONSTRAINT [CK_ReportTemplateAttributes] CHECK
((
[Col1] IS NOT NULL AND [Col2] IS NULL AND [Col3] IS NULL AND [Col4] IS NULL
OR
[Col1] IS NULL AND [Col2] IS NOT NULL AND [Col3] IS NULL AND [Col4] IS NULL
OR
[Col1] IS NULL AND [Col2] IS NULL AND [Col3] IS NOT NULL AND [Col4] IS NULL
OR
[Col1] IS NULL AND [Col2] IS NULL AND [Col3] IS NULL AND [Col4] IS NOT NULL
));
GO;
This works, but it seems to me that there may be a more elegant way to achieve the same result (for example, this questionnaire wants to check that at least 1 field is not zero, and the keyword COALESCEworks well in this case).