WHEN cd.Monday = 1 THEN 7
WHEN cd.Tuesday = 1 THEN 6
WHEN cd.Wednesday = 1 THEN 5
WHEN cd.Thursday = 1 THEN 4
WHEN cd.Friday = 1 THEN 3
WHEN cd.Saturday = 1 THEN 2
WHEN cd.Sunday = 1 THEN 1
END AS ContractDetailFirstDay,
You may not have any say in this, but one thing that can be done is you can create a persisted calculated column in the contract details table. The calculation would be based on this logic and store one of the values of 1-7. That way you could just pull the value without any on the fly calculations.
----------------------------------------------------