更新sql 2008后返回空白单元格的表类型

时间:2016-04-11 15:28:26

标签: sql sql-server sql-server-2008

我有一个select查询返回两个结果,我想要的是将它们保存在表类型的变量中。我就是这样做的:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper((HttpServletRequest) request) {

        @Override
        public Enumeration<String> getHeaderNames() {
            List<String> hdrs = Collections.list(super.getHeaderNames())
                    .stream()
                    .filter(h -> !h.equals(IF_MODIFIED_SINCE))
                    .collect(Collectors.toList());

            return Collections.enumeration(hdrs);
        }
    };
    chain.doFilter(wrapper, response);
}

这里,当我运行子查询时,我看到CMed是25而CPerc是43.但是,当我执行declare @CompletedTotalValues table (CMedian int, CPerc int); update @CompletedTotalValues set CMedian = t.CMed, CPercentile = t.CPerc from( Select CMed = dbo.median(case when cr.Priority = 1 then cr.Days else null end), CPerc = dbo.Percentile90(case when cr.Priority = 1 then cr.Days else null end) from A a inner join B b on b.Id = a.Id where b.StatusId = 3 ) t; 时,它将两列都返回空白(它没有显示的值)。我的错误在哪里?任何建议将不胜感激

2 个答案:

答案 0 :(得分:0)

如果我按照您共享的查询进行操作,那么您尝试更新时甚至不会在表格变量中首先插入任何数据。是吗?

答案 1 :(得分:0)

为什么不直接插入数据?

DECLARE @CompletedTotalValues TABLE (CMedian INT, CPerc INT);
INSERT @CompletedTotalValues (CMedian, CPerc)
SELECT  CMed = dbo.median(CASE WHEN cr.Priority = 1 THEN cr.Days END),
        CPerc = dbo.Percentile90(CASE WHENn cr.Priority = 1 THEN cr.Days END)
FROM    A 
        INNER JOIN B ON b.Id = a.Id
WHERE   b.StatusId = 3;