SQL Server引用计算列

编程入门 行业动态 更新时间:2024-10-11 17:26:57
本文介绍了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引用计算列

本文发布于:2023-10-31 09:07:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SQL   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!