保存视图后,我的别名会一直重命名为Expr1,Expr2等。我在视图中有多个CASE WHEN THEN语句在每个case语句中都有相同的别名(X0,Y0和Z0。)基本上所有case语句在第一个case语句之后用这个Expr1 Expr2替换了我的别名。 任何帮助将非常感激。我也尝试在别名周围放置方括号,但这不起作用。
我还应该注意,当我去保存时,我从SQL Server Management Studio收到有关我的order by子句的警告。它可能不相关但你永远不知道。
SELECT
TOP (100) PERCENT
s.dtmEvaluation AS SurgeryDate,
p.idPatient,
d.strLead AS LeadType,
ds.strDBSSite AS Target,
CASE
WHEN intSide = 0 THEN 'L'
ELSE 'R'
END AS Side,
ROUND(s.dblACX, 2, 1) AS ACX,
ROUND(s.dblACZ, 2, 1) AS ACY,
ROUND(s.dblACZ, 2, 1) AS ACZ,
ROUND(s.dblPCX, 2, 1) AS PCX,
ROUND(s.dblPCY, 2, 1) AS PCY,
ROUND(s.dblPCZ, 2, 1) AS PCZ,
ROUND(s.dblInitX, 2, 1) AS InitialX,
ROUND(s.dblInitY, 2, 1) AS [Initial Y],
ROUND(s.dblInitZ, 2, 1) AS [Initial Z],
s.dblACPCAngle AS InitialACPCAngle,
s.dblCenterAngle AS InitialCLangle,
s.dblMicroPasses AS MicroPasses,
s.dblMacroPasses AS MacroPasses,
ROUND(s.dblFinalX, 2, 1) AS FinalX,
ROUND(s.dblFinalY, 2, 1) AS FinalY,
ROUND(s.dblFinalZ, 2, 1) AS FinalZ,
ROUND(s.dblMeasuredX, 2, 1) AS MeasX,
ROUND(s.dblMeasuredY, 2, 1) AS MeasY,
ROUND(s.dblMeasuredZ, 2, 1) AS MeasZ,
s.dblMeasuredACPCAngle,
s.dblMeasuredCtrAngle,
ROUND(SQRT(POWER(s.dblMeasuredX - s.dblFinalX, 2) + POWER(s.dblMeasuredY - s.dblFinalY, 2) + POWER(s.dblMeasuredZ - s.dblFinalZ,2)), 2, 1) AS Delta,
CASE
WHEN s.intSide = 1 THEN s.dblMeasuredx + ((dblelectrodelength - 1) + 0 * (dblelectrodespacing + dblelectrodelength) + (dblelectrodelength / 2)) * SIN(RADIANS(dblMeasuredCtrAngle))
ELSE dblMeasuredx - ((dblelectrodelength - 1) + 0 * (dblelectrodespacing + dblelectrodelength) + (dblelectrodelength / 2)) * SIN(RADIANS(dblMeasuredCtrAngle))
END AS X0,
s.dblMeasuredY +
(((d.dblElectrodeLength - 1)
+ 0 * (d.dblElectrodeSpacing + d.dblElectrodeLength)) +
d.dblElectrodeLength / 2) * COS(RADIANS(s.dblMeasuredACPCAngle))
* COS(RADIANS(s.dblMeasuredCtrAngle)) AS Y0,
s.dblMeasuredZ + (((d.dblElectrodeLength - 1) + 0 *
(d.dblElectrodeSpacing + d.dblElectrodeLength))
+ d.dblElectrodeLength / 2) *
SIN(RADIANS(s.dblMeasuredACPCAngle)) *
COS(RADIANS(s.dblMeasuredCtrAngle)) AS Z0,
CASE
WHEN intSide = 1 THEN dblMeasuredx +
((dblelectrodelength - 1) + 1 * (dblelectrodespacing +
dblelectrodelength) + (dblelectrodelength / 2))
* SIN(RADIANS(dblMeasuredCtrAngle))
ELSE dblMeasuredx -
((dblelectrodelength - 1) + 1 * (dblelectrodespacing +
dblelectrodelength) + (dblelectrodelength / 2))
* SIN(RADIANS(dblMeasuredCtrAngle))
END AS Expr1,
s.dblMeasuredY + (((d.dblElectrodeLength - 1) + 1 *
(d.dblElectrodeSpacing + d.dblElectrodeLength))
+ d.dblElectrodeLength / 2) *
COS(RADIANS(s.dblMeasuredACPCAngle)) *
COS(RADIANS(s.dblMeasuredCtrAngle)) AS Expr2,
s.dblMeasuredZ + (((d.dblElectrodeLength - 1) + 1 *
(d.dblElectrodeSpacing + d.dblElectrodeLength)) + d.dblElectrodeLength /
2)
* SIN(RADIANS(s.dblMeasuredACPCAngle)) *
COS(RADIANS(s.dblMeasuredCtrAngle)) AS Expr3,
CASE
WHEN intSide = 1 THEN dblMeasuredx + ((dblelectrodelength - 1)
+ 2 * (dblelectrodespacing + dblelectrodelength) +
(dblelectrodelength / 2)) * SIN(RADIANS(dblMeasuredCtrAngle))
ELSE dblMeasuredx - ((dblelectrodelength - 1)
+ 2 * (dblelectrodespacing + dblelectrodelength) +
(dblelectrodelength / 2)) * SIN(RADIANS(dblMeasuredCtrAngle))
END AS
Expr4,
s.dblMeasuredY + (((d.dblElectrodeLength - 1) + 2 *
(d.dblElectrodeSpacing + d.dblElectrodeLength)) + d.dblElectrodeLength
/ 2)
* COS(RADIANS(s.dblMeasuredACPCAngle)) *
COS(RADIANS(s.dblMeasuredCtrAngle)) AS Expr5,
s.dblMeasuredZ +
(((d.dblElectrodeLength - 1)
+ 2 * (d.dblElectrodeSpacing + d.dblElectrodeLength)) +
d.dblElectrodeLength / 2) * SIN(RADIANS(s.dblMeasuredACPCAngle)) *
COS(RADIANS(s.dblMeasuredCtrAngle))
AS Expr6,
CASE
WHEN intSide = 1 THEN dblMeasuredx +
((dblelectrodelength - 1) + 3 * (dblelectrodespacing +
dblelectrodelength) + (dblelectrodelength / 2))
* SIN(RADIANS(dblMeasuredCtrAngle))
ELSE dblMeasuredx -
((dblelectrodelength - 1) + 3 * (dblelectrodespacing +
dblelectrodelength) + (dblelectrodelength / 2))
* SIN(RADIANS(dblMeasuredCtrAngle))
END AS Expr7,
s.dblMeasuredY + (((d.dblElectrodeLength - 1) + 3 *
(d.dblElectrodeSpacing + d.dblElectrodeLength))
+ d.dblElectrodeLength / 2) *
COS(RADIANS(s.dblMeasuredACPCAngle)) *
COS(RADIANS(s.dblMeasuredCtrAngle)) AS Expr8,
s.dblMeasuredZ + (((d.dblElectrodeLength - 1) + 3 *
(d.dblElectrodeSpacing + d.dblElectrodeLength)) + d.dblElectrodeLength /
2)
* SIN(RADIANS(s.dblMeasuredACPCAngle)) *
COS(RADIANS(s.dblMeasuredCtrAngle)) AS Expr9,
s.dblAtlasScaleX,
s.dblAtlasScaleY,
s.dblAtlasScaleZ,
s.dblAtlasMovementX,
s.dblAtlasMovementY,
s.dblAtlasMovementZ,
s.dblAtlasRotationX,
s.dblAtlasRotationY,
s.dblAtlasRotationZ
FROM dbo.tblDBSSurgery AS s
INNER JOIN dbo.tblPatientDemographics AS p
ON p.idPatient =
s.idPatient
LEFT OUTER JOIN dbo.tblLookupLeads AS d
ON d.idLead = s.intLeadType
LEFT OUTER JOIN dbo.tblLookupDBSSites AS ds
ON ds.idDBSSite = s.intSite
WHERE (s.intProcedure = 0
OR s.intProcedure = 2)
AND (s.blnOutside = 0)
AND (NOT
(p.strMRN = '09999999'))
AND (NOT (p.strMRN = '08888888'))
ORDER BY surgerydate