I have two table like
First table
FtID ItemName Days
---------------------------------------
1 Drive 10
2 Run 5
3 Read 21
Second Table
StID FtID Completed (bit) DateTime
-----------------------------------------------------
1 1 0 07/11/2011
2 1 1 08/11/2011
3 1 1 09/11/2011
4 1 0 10/11/2011
5
I need to select from both tables and get data like you can see below
ItemName Days DaysCompleted DaysIncompleted PercentageCompletion DaysLeft
---------------------------------------------------------------------------------------
Drive 10 2 2 40% 6
As JNK noted if Completed is Indeed a BIT you’ll need to cast to an integer (or use SUM/CASE as with his answer). Also I outputted Percentage Complete as
40if you want.40then you’ll need to cast to decimal if t1.Days is not already a decimal.