字符串而不是sql查询结果 [英] String instead of sql query result

查看:91
本文介绍了字符串而不是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

推荐答案

为什么要这样?

好吧,您可以使用案例 [
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查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆