I’m trying to get hours and minutes from a total minute count. I got this bit of code from another website, but the first part doesn’t seem to work:
cast(TimeToAdd/60 as varchar) + ' hours ' +
cast(TimeToAdd%60 as varchar) + ' minutes' as [Converted]
With TimeToAdd worth 75 minutes, the answer should be 1 hour 15 minutes, but all I am getting is 0 hour 15 minutes.
Here is the full SQL:
select pu.ProjectID, c.ClientName, p.ProjectTitle, sum(TimeToAdd) as TotalTime,
cast(TimeToAdd/60 as varchar) + ' hours ' +
cast(TimeToAdd%60 as varchar) + ' minutes' as [Converted]
from dbo.ProjectUsers pu
left join dbo.Projects p
on pu.ProjectID = p.ProjectID
left join dbo.ProjectTime pt
on p.ProjectID = pt.ProjectID
inner join dbo.Clients c
on p.ClientID = c.ClientID
where pu.StaffID = 3
group by pu.ProjectID, c.ClientName, p.ProjectTitle, pt.TimeToAdd
Any suggestions?
Use a subselect, so you can reference the SUMmed column by name: