Questions tagged [calculated-columns]

A calculated column is calculated from an expression that can use other columns in the same table

A calculated column is calculated from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators. The expression cannot be a subquery.

2235 questions
30
votes
2 answers

SQL Server 2005 Computed Column Is Persisted

I have some computed columns in a table and need to know if I should set Is Persisted to true. What are the advantages? Are there any disadvantages? What does 'Is Persisted' mean?
hilary
  • 684
  • 3
  • 9
  • 12
30
votes
6 answers

Using conditional to generate new column in pandas dataframe

I have a pandas dataframe that looks like this: portion used 0 1 1.0 1 2 0.3 2 3 0.0 3 4 0.8 I'd like to create a new column based on the used column, so that the df looks like this: portion used …
user3786999
  • 1,037
  • 3
  • 13
  • 24
29
votes
6 answers

SQL Server Reference a Calculated Column

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] =…
mhinton
  • 1,175
  • 1
  • 12
  • 24
27
votes
6 answers

Creating date in SQL Server 2008

Is there something similar to DATEFROMPARTS(year, month, day) in SQL Server 2008? I want to create a date using the current year and month, but my own day of the month. This needs to be done in one line in order to be used in a computed column…
Jaiesh_bhai
  • 1,778
  • 8
  • 26
  • 41
26
votes
2 answers

Creating a computed column in SQL Server 2008

I have a SQL Server 2008 database. This database has a Table called "Book". "Book" has the following properties: ID (int) Title (nvarchar(256)) PublishDate (datetime) I need to create a computed column called "AgeInMinutes". I'm not very familiar…
Phone Developer
  • 1,411
  • 4
  • 25
  • 36
26
votes
5 answers

Use value of a column for another column (SQL Server)?

lets say I have a huge select on a certain table. One value for a column is calculated with complex logc and its called ColumnA. Now, for another column, I need the value from ColumnA and add some other static value to it. Sample SQL: select…
grady
  • 12,281
  • 28
  • 71
  • 110
25
votes
2 answers

Why am I getting a an error when creating a generated column in PostgreSQL?

CREATE TABLE my_app.person ( person_id smallserial NOT NULL, first_name character varying(50), last_name character varying(50), full_name character varying(100) generated always as (concat(first_name, ' ', last_name)) STORED, …
24
votes
2 answers

Subquery as generated column in mysql?

Can I create a generated column in table A which sums up a column in table B with a tableA_id of the row in table A? Suppose I have a table of of families, and a table of children. I want a sum of the ages of the children for each family. ALTER…
23
votes
4 answers

Add column to the end of Pandas DataFrame containing average of previous data

I have a DataFrame ave_data that contains the following: ave_data Time F7 F8 F9 00:00:00 43.005593 -56.509746 25.271271 01:00:00 55.114918 -59.173852 31.849262 02:00:00 63.990762 -64.699492 …
LinnK
  • 385
  • 2
  • 4
  • 17
21
votes
2 answers

Postgres add column with initially calculated values

I'm looking to add a new column to a pre-existing table which is filled with values. The new column is going to be NOT NULL, and so for each pre-existing row it will need a value. I'm looking for the initial values on this column to be calculated…
Gershom Maes
  • 7,358
  • 2
  • 35
  • 55
21
votes
2 answers

What is the data type of a computed column?

When you CREATE TABLE using CASE expression to create a computed column, you do not explicitly define the data type of this column: CREATE TABLE OrderDetail ( OrderID INT , ProductID INT , Qty INT , OrderDate DATETIME , ShipDate DATETIME , STATUS AS…
jrara
  • 16,239
  • 33
  • 89
  • 120
20
votes
2 answers

Pandas min() of selected row and columns

I am trying to create a column which contains only the minimum of the one row and a few columns, for example: A0 A1 A2 B0 B1 B2 C0 C1 0 0.84 0.47 0.55 0.46 0.76 0.42 0.24 0.75 1 0.43 …
yash.trojan.25
  • 211
  • 1
  • 3
  • 8
19
votes
5 answers

Convert computed column to regular column

I have a persisted computed column in a large table in in SQL Server 2005. I want to convert it to a regular column, keeping current values. Do I have to recreate the column and update the entire table in transaction, or is it possible to just alter…
George Polevoy
  • 7,450
  • 3
  • 36
  • 61
18
votes
1 answer

How to change a normal column to "computed" column

I have a table in MSSQL server 2008. I would like to change one of the column in that table to computed column. Could somebody tell me how do I do that ?
Relativity
  • 6,690
  • 22
  • 78
  • 128
18
votes
1 answer

Why does the Execution Plan include a user-defined function call for a computed column that is persisted?

I have a table with 2 computed columns, both of which has "Is Persisted" set to true. However, when using them in a query the Execution Plan shows the UDF used to compute the columns as part of the plan. Since the column data is calculated by the…