sqlServer变量运用示例

1.定义变量
declare @startTime varchar(255)
-- 2.设置变量
set @startTime = convert(VARCHAR(10),dateadd(day,-1,getdate()),120)+'%'
--  也可以从这里指定要查询的日期
-- set @startTime = '2017-04-05%'
-- 显示指定的日期
PRINT(@startTime)
select REPLACE(@startTime,'%','') as 日期,当日活跃用户,当日新增用户 from
(
        -- 3.查询当日活跃用户
        select '01' as id,count(1) as 当日活跃用户 from
        (
                select DISTINCT usId from loginLog t where CONVERT(varchar(100), t.addTime, 25) like @startTime
        ) as a
) as a2,
-- 4.查询当日新增用户
(select '01' as id,count(1) as 当日新增用户 from userT t where CONVERT(varchar(100), t.addTime, 25) like @startTime) b
where a2.id = b.id;

文章标题:sqlServer变量运用示例
分享链接:http://lszwz.com/article/podgio.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款