我的数据库中有一个表格,其中包含字段
Column Name Data Type
=========== =============
Empno varchar(10)
Surname varchar(10)
ShiftDiffInd varchar (1)
PrevEmpGrossy money
NonTaxYtodate money
我想从这个表中只取这两个字段'ShiftDiffInd' 'NonTaxYtodate'
的字段名称。不是这个领域的价值,那我该怎么做呢
我希望我的回归像这样
==============
ShiftDiffInd
NonTaxYtodate
答案 0 :(得分: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
答案 1 :(得分:1)
SELECT 'ShiftDiffInd' as ShiftDiffInd, 'NonTaxYtodate' as NonTaxYtodate , * FROM Master
答案 2 :(得分:1)
select column_name from INFORMATION_SCHEMA.COLUMNS
where 1=1
and TABLE_NAME = 'Master'
and COLUMN_NAME in ('ShiftDiffInd','NonTaxYtodate')
答案 3 :(得分:1)
我之前误解了您的问题,尝试使用以下查询,您会得到预期的结果:
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME=OBJECT_NAME(OBJECT_ID('Master'))
AND COLUMN_NAME IN ('ShiftDiffInd','NonTaxYtodate')