简体   繁体   中英

Select specific column names

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?

You could use a case to translate the column name:

select  case COLUMN_NAME 
        when 'Doub' then 'DB'
        else COLUMN_NAME 
        end
from    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM