项目中用到的sql语句

 SELECT *
      
FROM(  SELECT ResourceBooking.*,
                    CustomerInformation.CustomerName 
as CustomerName,
                    CustomerInformation.Gender
+'/'+ltrim(str(datediff(year,isnull(CustomerInformation.DateOfBirth,0),getDate()))) as AgeAndBirth,
                    ResourceBookingType.BookingName 
AS BookingName,
                    ResourceBookingType.BookingDescription 
AS BookingDescription,
                    RES.ResourceTypeID 
as ResourceTypeID,
                    RES.ResourceSubTypeID 
as ResourceSubTypeID,
                    RES.ResourceGroupID 
as ResourceGroupID,
                    RES.ResourceTableID 
as ResourceTableID,
                    RES.ResourcePKField 
as ResourcePKField,
                    RES.IDDescription 
as IDDescription,
                    RES.DicriptionName 
as EmployeeUserName
                    
FROM ResourceBooking LEFT JOIN CustomerInformation
                    
ON ltrim(rtrim(ResourceBooking.PatientID)) = ltrim(rtrim(CustomerInformation.CustomerID))
                    
LEFT JOIN ResourceBookingType
                    
ON ResourceBooking.BookingTypeID=ResourceBookingType.BookingTypeID
                    
LEFT JOIN (SELECT Resource.*,
                    IDDescription 
=  CASE ResourceTables.ResourceTableName WHEN 'PayrollEmployees' THEN (SELECT EmployeeID From PayrollEmployees where EmployeeID = Resource.ResourcePKField )
                                                                           
WHEN 'Facility' THEN (SELECT FacilityID FROM Facility WHERE FacilityID =Resource.ResourcePKField)
                                                                           
END,
                    DicriptionName 
= CASE ResourceTables.ResourceTableName WHEN  'PayrollEmployees' then (SELECT EmployeeUserName From PayrollEmployees where EmployeeID = Resource.ResourcePKField )
                                                                           
WHEN 'Facility' THEN (SELECT FacilityDescription FROM Facility WHERE FacilityID =Resource.ResourcePKField)
                                                                           
END
                    
FROM  Resource left join ResourceTables ON Resource.ResourceTableID = ResourceTables.ResourceTableID) AS RES
                    
ON ResourceBooking.ResourceID = RES.ResourceID
      ) 
AS ResourceBooking
      
WHERE (ResourceBooking.CompanyID = @CompanyID)
      
AND (ResourceBooking.DivisionID = @DivisionID)
      
AND (ResourceBooking.DepartmentID = @DepartmentID)
      
AND (ResourceBooking.ResourceBookingState <>'3')
      
AND (((@ResourceGroupID <>'' or @ResourceGroupID is not null)  and ResourceBooking.ResourceGroupID= @ResourceGroupIDor (@ResourceGroupID='' or @ResourceGroupID is null ))
      
AND (((@EmployeeID <>'' or @EmployeeID is not nulland ResourceBooking.IDDescription=@EmployeeIDor (@EmployeeID='' or @EmployeeID is null))
      
AND (cast(convert(nvarchar(30),ResourceBooking.FromDateTime,10)as DateTime)=cast(@FromDateTime as DateTime))
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值