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
6
votes
3 answers

Identify if a column is Virtual in Snowflake

Snowflake does not document its Virtual Column capability that uses the AS clause. I am doing a migration and needing to filter out virtual columns programatically. Is there any way to identify that a column is virtual? The Information…
6
votes
1 answer

Computed Column Help - TSQL

CREATE TABLE [dbo].[tblLocations]( [latitude] [float] NOT NULL, [longitude] [float] NOT NULL, [location] [varchar](500) NOT NULL, [timestamp] [datetime] NOT NULL, [point] [geography] AS geography::Point(latitude, longitude, 4326)…
slandau
  • 23,528
  • 42
  • 122
  • 184
6
votes
2 answers

How to check if computed column is persisted?

How to check if computed column is persisted? (MS SQL Server)
Alex
  • 2,438
  • 23
  • 30
6
votes
2 answers

Score entity based on its likes count and creation time

When reading from database, I want to sort my Post entities based on two factors: likes count (the more the better) age (the newer the better) Currently I have implemented it this way (as a calculated value): @Entity public class Post { //…
Mahozad
  • 18,032
  • 13
  • 118
  • 133
6
votes
2 answers

Using CASE on a Calculated Column in SQL Server 2012

I have a database called temp, with daily stock prices: Ticker Date price ABC 01/01/13 100.00 ABC 01/02/13 101.50 ABC 01/03/13 99.80 ABC 01/04/13 95.50 ABC 01/05/13 78.00 XYZ 01/01/13 11.50…
Coding_Newbie
  • 365
  • 1
  • 3
  • 11
6
votes
1 answer

SQL Server Calculated Column

I have two columns, both int's, Wins and Losses. I have a calculated column WinPercentage as a decimal(14,3), I want this to be: WinPercentage = (Wins + Losses) / Wins What's the syntax for that?
Scott
  • 4,066
  • 10
  • 38
  • 54
6
votes
2 answers

Inconsistent results with NEWID() and PERSISTED computed column

I am getting odd results when using NEWID() in combination with a persistent computed column. Am I using some function wrong? Not using persisted when creating the column, and therefore calculating values when selecting them, will return correct…
Kristofer
  • 675
  • 7
  • 15
6
votes
3 answers

MySQL: Selecting the rows having min value of a computed column

The naive way of doing this that comes to mind would be: SELECT name, lev FROM (SELECT name, levenshtein(name, *parameter*) as lev FROM my_table) WHERE lev = (SELECT MIN(lev) FROM (SELECT name, levenshtein(name, *parameter*) as lev FROM my_table…
Vermillon
  • 253
  • 1
  • 3
  • 8
6
votes
2 answers

Why is my CASE expression non-deterministic?

I am trying to create a persisted computed column using CASE expression: ALTER TABLE dbo.Calendar ADD PreviousDate AS case WHEN [Date]>'20100101' THEN [Date] ELSE NULL END PERSISTED MSDN clearly says that CASE is deterministic,…
A-K
  • 16,804
  • 8
  • 54
  • 74
6
votes
2 answers

Syncing column width of between tables in two different frames, etc

For reasons which are somewhat unavoidable (lots of legacy code, compatibility, design needs) I have the following problem: I have two tables, one directly below the other, but split between two frames (see the pseudo-example below my sig.). I…
Rex Butler
  • 1,030
  • 2
  • 13
  • 24
6
votes
3 answers

Mysql calculation in select statement

I have been doing my office work in Excel.and my records have become too much and want to use mysql.i have a view from db it has the columns "date,stockdelivered,sales" i want to add another calculated field know as "stock balance". i know this is…
Law
  • 129
  • 1
  • 3
  • 10
6
votes
2 answers

Computed column index

I have a table Com_Main which contains column CompanyName nvarchar(250). It has average length of 19, max length = 250. To improve performance I want to add a computed column left20_CompanyName which holds the first 20 characters of…
5
votes
3 answers

Any simpler way to assign multiple columns in Python like R data.table :=

I'm wondering if there's any simpler way to assign multiple columns in Python, just like the := in R data.table. For example, in Python I would have to write like this: df['Col_A'] = df.A/df.B df['Col_B'] = df.C/df.D df['Col_C'] = df.E/df.F *…
5
votes
6 answers

In Entity Framework can I create a computed column that calculates all the values from every row?

I have 3 main columns (Points, TotalPoints, DateCreated) in a table using Entity Framework. Scenario - Think of the "Fun Arcade" where you earn tokens for playing games and can then exchange those tokens for gifts. So your "Points" count or token…
chuckd
  • 13,460
  • 29
  • 152
  • 331
5
votes
2 answers

Access SQL computed columns through ActiveRecord

I have a Person model, which includes a property representing the data of birth (birth_date). I also have a method called age(), which works out the current age of the person. I now have need to run queries based on the person's age, so I have…
kim3er
  • 6,306
  • 4
  • 41
  • 69