1

So I have this:

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

And it works great. I get all the column names that I want, in c# I use this to populate a drop down with the column names. however, one of my column names, "Doub" I would like to change. So playing around with it I tried:

SELECT        COLUMN_NAME.Doub AS 'DB'
FROM            INFORMATION_SCHEMA.COLUMNS
WHERE        (TABLE_NAME = 'Batting')

and a variation of that, and the error is the mulitplart identifier could not be bound. How can i change that column name in this query?

4

1 回答 1

3

您可以使用 acase来翻译列名:

select  case COLUMN_NAME 
        when 'Doub' then 'DB'
        else COLUMN_NAME 
        end
from    ...
于 2013-05-11T17:20:40.573 回答