本文介绍了sql查询给出“无效的列名”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的查询:

this is my query:

DECLARE @columns VARCHAR(8000)

SELECT @columns = COALESCE(@columns + ',[' + cast(Date as varchar) + ']',
'[' + cast(Date as varchar)+ ']')
FROM Absence
GROUP BY Date DECLARE @query VARCHAR(8000) SET @query = ' SELECT * FROM (SELECT Name , Code, Section, Date FROM Absence) up PIVOT (COUNT(Code) FOR Date IN (' + @columns + '))  AS p WHERE Section LIKE A ' EXECUTE(@query)





它给出无效的列名'A'



it gives "Invalid column name 'A'"

推荐答案

GROUP BY Date DECLARE @query VARCHAR(8000) SET @query = ' SELECT * FROM (SELECT Name , Code, Section, Date FROM Absence) up PIVOT (COUNT() FOR Date IN (' + @columns + '))  AS p WHERE Section LIKE ''A'' ' EXECUTE(@query)


这篇关于sql查询给出“无效的列名”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 16:08