我有问题,我无法获得季度数据的总和。
我希望我的输出像这样:
$('.js-grid-text-0').append(' %');
$('.js-grid-text-1').append(' %');
和
data = get(handles.uitable1, 'data');
k = size(data,1)+1;
if k == 1
B = num2cell(data);
else
B = data;
end
B{k,1} = xrange;
B{k,2} = xmoment;
B{k,3} = xmad;
B{k,4} = xiqr;
B{k,5} = xstd;
B{k,6} = xvar;
set(handles.uitable1, 'data', B);
输出:
@startdate='5/17/2017'
用户选择两个日期,第一个是@startdate,另一个是@enddate, Enddate当然应该确定选择哪个季度,如果是5月那么它必须显示JUNE(第6个月)和季度的最后一天。
我的查询是这样的,但显然它不起作用,我试图混合数据函数中的东西
@enddate='5/27/2017
答案 0 :(得分:0)
不确定下面会有效,但值得一试:
declare @startdate date = (select getdate()- 60 )
declare @enddate date = (select getdate() - 30)
select @startdate, @enddate
declare @sql nvarchar(1000)
set @sql =
'SELECT bal.AccountNo,
SUM(bal.Sum) as ''' + replace(convert(nvarchar(10), DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, @enddate) +1, 0)), 101), '/', '') +'''
INNER JOIN dbo.Accounts AS acc
ON acc.AccountNo = bal.AccountNo
WHERE (bal.BalanceDate BETWEEN ''' + convert(varchar, @startdate, 101) + ''' AND ''' + convert(varchar, @enddate, 101) +''')
GROUP BY acc.AccountName'
print @sql
exec (@sql)
我不这么认为,除了上面的动态之外还有另一种方式。
答案 1 :(得分:0)
我的问题是从当前日期结束本季度,也不仅仅是季度结束,而是从当前日期到本季度末的月底
这是代码,我用来检索我的数据
DECLARE @startdate DATE; SET @startdate='5/2/2017';
DECLARE @enddate DATE; SET @enddate='6/13/2017'
DECLARE @datatype VARCHAR; SET @datatype=3;
SELECT bal.AccountNo,acc.AccountName ,
CASE @datatype WHEN 3 THEN SUM(bal.Sumn)END AS [balance]
FROM dbo.Balances AS bal
INNER JOIN dbo.Accounts AS acc
ON acc.AccountNo = bal.AccountNo
WHERE (bal.BalanceDate BETWEEN convert(varchar, @startdate, 101) AND
convert(varchar, @enddate, 101))
GROUP BY acc.AccountName,bal.AccountNo