SQL Server引用计算列 [英] SQL Server Reference a Calculated Column

查看:100
本文介绍了SQL Server引用计算列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条带计算列的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引用计算列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆