SELECT DATEDIFF(DAY,e.StartDate,e.EndDate)as totaldays,
(SELECT COUNT(TaskID) from ConstructionManagement c where
c.Co_ProjectID=e.ProjectID) as aa,CAST(CAST((SELECT
COUNT(TaskID) from ConstructionManagement c where
c.Co_ProjectID=e.ProjectID)AS
float)/CAST((DATEDIFF(DAY,e.StartDate,e.EndDate)) AS float)*100
AS nvarchar(20))+'%' as yy ,e.* FROM EngineeringManagement e
解析:DATEDIFF-时间差函数方法(day(定义查询出来的内容为什么日期格式:这里可以是(year | quarter | month | week | day | hour | minute | second | millisecond)), e.StartDate,e.EndDate(2个参数,第一个定义开始日期,第二个定义结束日期))
totaldays:接收刚才查出来的天数
aa:接收查询出来已经进行过的天数
yy:接收计算出来的百分比
cast:数据库类型转换