本文介绍了字符串而不是sql查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,我想执行查询以获取2个日期之间的日期.但是我的问题是我需要一个通用字符串而不是结果值 对于EG:查询结果:12-05-1658 我需要"h"而不是12-05-1658 编辑 ---------------------------- 此查询仅返回日期.我需要查找相应日期的状态
Hi Friends I want to execute a query for getting the date between 2 dates..But my problem is i need a common string instead of the result-value For EG: The query result:12-05-1658 I need ''h'' instead of 12-05-1658 EDIT ---------------------------- This query returns only date.I need to find the status of corresponding dates
select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' or Status='A' ) except select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='A'or Status='FL' or Status='H' ) intersect ( (select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' or Status='A' ) except select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' ) ) union (select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' or Status='A' ) except select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='A' or Status='H' ) ) union (select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' or Status='A' ) except select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='A' ) ) ) union (select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' or Status='A' ) except select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' ) ) union (select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' or Status='A' ) except select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='A' or Status='H' ) ) union (select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='H' or Status='A' ) except select distinct date from tblStdntAttndnce where Batch_Id='233' and MONTH(date)='6' and YEAR(date)='2011' and (Status='P'or Status='FL' or Status='A' ) ) order by DATE推荐答案
为什么要这样? 好吧,您可以使用案例 [ ^ ]语句(如果结果行较少),但如果结果行较多,则需要使用存储过程(带有CASE语句). Why do you want like that? Well, you can use CASE[^] statement for that(If result rows are less) but If result rows are more then you need use stored procedure(with CASE statement).
更多推荐
字符串而不是sql查询结果
发布评论