如何选择表格列而不指定列名称,并且可以对所有列

时间:2015-09-03 05:24:15

标签: sql sql-server join union

如何在不指定列名的情况下选择表列,并且可以对所有列应用相同的条件。 我正在使用以下SQL查询。我可以使用SQL Server中的单行查询获得相同的结果吗

SELECT FEE.admissionfees AS AMT
    ,'Admission Fee' amtType
FROM tblFeesDetails FEE
INNER JOIN tblStudentFeeSheet STF ON FEE.feesId = STF.feeId
WHERE feeId = 1
    AND enrollMentNo = 'EDU0001'
    AND FEE.admissionfees != 0

UNION

SELECT FEE.electricityAndBuildingMaintanance AS AMT
    ,'Elec. & Buld. Maint. Fee' amtType
FROM tblFeesDetails FEE
INNER JOIN tblStudentFeeSheet STF ON FEE.feesId = STF.feeId
WHERE feeId = 1
    AND enrollMentNo = 'EDU0001'
    AND FEE.electricityAndBuildingMaintanance != 0

UNION

SELECT FEE.functions AS AMT
    ,'Functions & Other Act. Fee' amtType
FROM tblFeesDetails FEE
INNER JOIN tblStudentFeeSheet STF ON FEE.feesId = STF.feeId
WHERE feeId = 1
    AND enrollMentNo = 'EDU0001'
    AND FEE.functions != 0

UNION

SELECT FEE.gamesAndExtraCurriculam AS AMT
    ,'Games & other Curriculam' amtType
FROM tblFeesDetails FEE
INNER JOIN tblStudentFeeSheet STF ON FEE.feesId = STF.feeId
WHERE feeId = 1
    AND enrollMentNo = 'EDU0001'
    AND FEE.gamesAndExtraCurriculam != 0

0 个答案:

没有答案