where 请求时间 between @startdate and @enddate
解决方案 »
- insert命令 怎么和 存储过程 联系起来?
- 请教SQL查询问题,请帮帮忙?
- sql2005 连接问题,急、急请各位大神帮帮忙!!!发帖三次了。。哎404
- 一个考虑了N天的查询汇总问题,大家帮忙,谢谢!!!
- 求一条SQL语句!!对不起,没分了,急啊!救救急!谢谢!
- 存储过程调用问题
- 一个SQL语句的问题,一定加分。
- 如何在一个触发器里,把INSERT,DELETE,UPDATE三个操作,用IF语句分开呢?
- B/S结构要服务器吗?还是直接连database??
- 我在ORACLE中建了一个数据库,不过删除时要输入密码, 是怎么回事?密码应输入什么?
- SQL表关联问题
- 在SQL SERVER2000如何控制LOCAL PACKAGE的访问权限?
这样用需要加小时段 如:2007-01-01 00:00:00 —2007-01-01 23:59:59
变量类型为datetime
set @startdate='2007-01-01 00:00:00'
set @enddate='2007-01-01 23:59:59
where 请求时间 between @startdate and @enddate
变量类型为varchar
set @startdate ='20070101'--取天为单位
set @enddate ='20070101'
where convert(varchar(8),请求时间,112) between @startdate and @enddate
(
@companyname varchar(100)=null,
@enddate datetime=null,
@startdate datetime=null)
as
beginselect 公司id,公司名称,sum(金额) as 总额 from
(
select * from [1]
union all
select * from [2]
) t
where 审批意见='同意'
and 公司名称=(case when @companyname is null then 公司名称 else @companyname end)
and 请求时间<(case when @enddate is null then 请求时间+1 else @enddate end)
and 请求时间>(case when @startdate is null then 请求时间-1 else @startdate end)
group by 公司id,公司名称 order by 公司idend这样不论你传几个变量,为空或不为空都无所谓了.如只传一个参数:exec test @companyname='微软公司'
declare @sql varchar(8000)
declare @f varchar(400)
set @f=(case when @enddate is null then '' else '
where 请求时间 < '''+@enddate+'''' end )+
(case when @startdate is null then '' else ' and 请求时间 > '''+@startdate+'''' end)+' '
set @sql='select 公司id,公司名称,sum(金额) as 总额 from
(
select * from 1 '+@f+
' union all
select * from 2 '+@f+
') t where 审批意见=''同意'''+
(case when isnull(@corpname,'')='' then ' ' else ' and 公司名称='''+@companyname+''' ' end)+'
group by 公司id,公司名称 order by 公司id'
exec(@sql)
select 公司id,公司名称,sum(金额) as 总额 from
(
select * from [1]
union all
select * from [2]
) t
中并没有相关于"请求时间"的概念,这个时侯把
and 请求时间<(case when @enddate is null then 请求时间+1 else @enddate end)
and 请求时间>(case when @startdate is null then 请求时间-1 else @startdate end
加到这个t表中能够行得通么,小弟还不是很了解
select 公司id,公司名称,sum(金额) as 总额 from
(
select * from [1]
union all
select * from [2]
) t
中并没有相关于"请求时间"的概念,这个时侯把
and 请求时间<(case when @enddate is null then 请求时间+1 else @enddate end)
and 请求时间>(case when @startdate is null then 请求时间-1 else @startdate end
加到这个t表中能够行得通么,小弟还不是很了解
select 公司id,公司名称,sum(金额) as 总额 from
(
select * from [1]
union all
select * from [2]
) t
中并没有相关于"请求时间"的概念,这个时侯把
and 请求时间<(case when @enddate is null then 请求时间+1 else @enddate end)
and 请求时间>(case when @startdate is null then 请求时间-1 else @startdate end
加到这个t表中能够行得通么,小弟还不是很了解