我有一条带计算列的select语句,我想在另一列中使用一个计算列的值。这可能吗?这是一个人为的示例,以显示我要执行的操作。
I have a select statement with calculated columns and I would like to use the value of one calculated column in another. Is this possible? Here is a contrived example to show what I am trying to do.
SELECT [calcval1] = CASE Statement, [calcval2] = [calcval1] * .25推荐答案
否。
select中单行的所有结果都是原子的。也就是说,您可以将它们视为并行发生并且彼此不依赖。
All the results of a single row from a select are atomic. That is, you can view them all as if they occur in parallel and cannot depend on each other.
如果您要引用计算列,则需要更新在选择期间要更改结果的公式输入。
If you're referring to computed columns, then you need to update the formula's input for the result to change during a select.
将计算列视为宏或迷你视图,每当调用它们时都会注入一些计算。
Think of computed columns as macros or mini-views which inject a little calculation whenever you call them.
例如,这些列将始终是相同的:
For example, these columns will be identical, always:
-- assume that 'Calc' is a computed column equal to Salaray*.25 SELECT Calc, Salary*.25 Calc2 FROM YourTable还请记住持续选项不会对此进行任何更改。它会将值保持在适合索引编制的范围内,但原子性不会改变。
Also keep in mind that the persisted option doesn't change any of this. It keeps the value around which is nice for indexing, but the atomicity doesn't change.
更多推荐
SQL Server引用计算列
发布评论