所以我有这个:
CREATE PROCEDURE getBattingColumnNames
AS
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Batting'
AND COLUMN_NAME NOT IN ('playerID','yearID','stint','teamID','lgID', 'G_batting','GIDP','G_old');
GO
它很棒。我得到了我想要的所有列名,在c#中我使用它来填充列名称的下拉列表。但是,我的一个专栏名称“Doub”我想改变。所以玩弄它我试过了:
SELECT COLUMN_NAME.Doub AS 'DB'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (TABLE_NAME = 'Batting')
及其变体,错误是mulitplart标识符无法绑定。如何在此查询中更改该列名?
答案 0 :(得分:3)
您可以使用case
翻译列名:
select case COLUMN_NAME
when 'Doub' then 'DB'
else COLUMN_NAME
end
from ...