Say I have the following SQL:SELECT     amount,    amount*.1,    (amount*1)+3,    ((amount*1)+3)/2,    (((amount*1)+3)/2)+37FROM tableInstead of repeating that identical code every time, I really want to be able to do something like this:SELECT    amount,    amount*.1 AS A,    A+3 AS B,    B/2 AS C,    C+37 AS D,FROM tableBut this code doesn't work.So, is there another way to avoid duplication in the working query that I have?
Remove duplication in SELECT statement
sql;sql server
That's not how SQL works. As mentioned in the SO answer linked by @rolfl:You can only refer to a column alias in an outer select, so unless you recalculate all the previous values for each column you'd need to nest each level, which is a bit uglyWhich means:SELECT amount, A, B, C, C+37 DFROM (SELECT amount, A, B, B/2 C      FROM (SELECT amount, A, A+3 B            FROM (SELECT amount, amount*0.1 A FROM table) firstPass) secondPass) thirdPassThat said, the last comma in your 2nd snippet is a pseudo syntax error (given it's a pseudo query)