-1

我的数据库中有一个 Master 表,其中包含字段

    Column Name       Data Type 
    ===========     =============

    Empno          varchar(10)
    Surname        varchar(10)
    ShiftDiffInd   varchar (1)
    PrevEmpGrossy  money
    NonTaxYtodate  money

我想从这个表中只取这两个字段的字段名'ShiftDiffInd' 'NonTaxYtodate'。不是这个字段的值,所以我该怎么做

我想要我的回报 像这样

==============
ShiftDiffInd
NonTaxYtodate
4

4 回答 4

2
select
   syscolumns.name as [Column]
from 
   sysobjects, syscolumns 
where sysobjects.id = syscolumns.id
and   sysobjects.name = 'Master'
and (syscolumns.name = 'ShiftDiffInd' or syscolumns.name = 'NonTaxYtodate')
order by syscolumns.name
于 2013-03-18T11:20:42.640 回答
1
SELECT 'ShiftDiffInd' as ShiftDiffInd, 'NonTaxYtodate' as NonTaxYtodate , * FROM Master
于 2013-03-18T11:23:07.520 回答
1
 select column_name from INFORMATION_SCHEMA.COLUMNS
where 1=1
    and TABLE_NAME = 'Master'
    and COLUMN_NAME in ('ShiftDiffInd','NonTaxYtodate')
于 2013-03-18T11:29:46.920 回答
1

我之前误解了您的问题,尝试使用以下查询,您会得到预期的结果:

 SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME=OBJECT_NAME(OBJECT_ID('Master'))
AND COLUMN_NAME IN ('ShiftDiffInd','NonTaxYtodate')
于 2013-03-18T11:49:14.990 回答