问题描述:员工A能够看到所在部门的员工差假信息,同时要求可以看到公司所有员工的差假信息。
解决办法:
1、SQL查询语句1查询员工A所在部门的员工差假信息
SELECT OffCategory, pwcCreatorNm, pwcCreatorDeptNm, SDateTime, EDateTime, OffHours, Category.CategoryID, pwcUniqueID, sn, CreateTime FROM LeaveInfo
WHERE pwcCreatorDeptNm=’IT’
ORDER BY OffCategory, pwcCreatorDeptNm, SDateTime
2、SQL查询语句2查询公司所有员工的出差信息
SELECT OffCategory, pwcCreatorNm, pwcCreatorDeptNm, SDateTime, EDateTime, OffHours, Category.CategoryID, pwcUniqueID, sn, CreateTime FROM LeaveInfo
WHERE LeaveInfo.OffCategory='出差'
ORDER BY OffCategory, pwcCreatorDeptNm, SDateTime
3、整合查询结果:
SELECT OffCategory, pwcCreatorNm, pwcCreatorDeptNm, SDateTime, EDateTime, OffHours, Category.CategoryID, pwcUniqueID, sn, CreateTime FROM LeaveInfo
WHERE pwcCreatorDeptNm=’IT’
UNION
SELECT OffCategory, pwcCreatorNm, pwcCreatorDeptNm, SDateTime, EDateTime, OffHours, Category.CategoryID, pwcUniqueID, sn, CreateTime FROM LeaveInfo
WHERE LeaveInfo.OffCategory='出差'
ORDER BY OffCategory, pwcCreatorDeptNm, SDateTime
备注:
1、 UNION联合两个或多个查询结果,并去除重复的查询记录;UNION ALL联合两个或多个查询结果。注意对查询结果排序时,order by仅在最后使用。
2、 类似这样的需求一般用SQL语句来实现,数据处理是SQL的强项。而不要用.net的数据集来实现。
解决办法:
1、SQL查询语句1查询员工A所在部门的员工差假信息
SELECT OffCategory, pwcCreatorNm, pwcCreatorDeptNm, SDateTime, EDateTime, OffHours, Category.CategoryID, pwcUniqueID, sn, CreateTime FROM LeaveInfo
WHERE pwcCreatorDeptNm=’IT’
ORDER BY OffCategory, pwcCreatorDeptNm, SDateTime
2、SQL查询语句2查询公司所有员工的出差信息
SELECT OffCategory, pwcCreatorNm, pwcCreatorDeptNm, SDateTime, EDateTime, OffHours, Category.CategoryID, pwcUniqueID, sn, CreateTime FROM LeaveInfo
WHERE LeaveInfo.OffCategory='出差'
ORDER BY OffCategory, pwcCreatorDeptNm, SDateTime
3、整合查询结果:
SELECT OffCategory, pwcCreatorNm, pwcCreatorDeptNm, SDateTime, EDateTime, OffHours, Category.CategoryID, pwcUniqueID, sn, CreateTime FROM LeaveInfo
WHERE pwcCreatorDeptNm=’IT’
UNION
SELECT OffCategory, pwcCreatorNm, pwcCreatorDeptNm, SDateTime, EDateTime, OffHours, Category.CategoryID, pwcUniqueID, sn, CreateTime FROM LeaveInfo
WHERE LeaveInfo.OffCategory='出差'
ORDER BY OffCategory, pwcCreatorDeptNm, SDateTime
备注:
1、 UNION联合两个或多个查询结果,并去除重复的查询记录;UNION ALL联合两个或多个查询结果。注意对查询结果排序时,order by仅在最后使用。
2、 类似这样的需求一般用SQL语句来实现,数据处理是SQL的强项。而不要用.net的数据集来实现。