Adding Computed Columns in SQL Server | SQLYoga - PowerPoint PPT Presentation

About This Presentation
Title:

Adding Computed Columns in SQL Server | SQLYoga

Description:

Enhance your SQL SERVER skills by discovering how to generate a comma separated list with SELECT statement in this SQLYoga article. – PowerPoint PPT presentation

Number of Views:0
Slides: 8
Provided by: sqlyoga
Tags:

less

Transcript and Presenter's Notes

Title: Adding Computed Columns in SQL Server | SQLYoga


1
Adding
W W W . S Q L Y O G A . C O M
01/07
  • Computed Columns in SQL Server

2
02/07 A scenario that required me to add one
calculated column came up today. When a column
is computed, it can be used in queries just like
any other column and allows us to change one or
more columns from the same table.
3
03/07
Lets try it
Create One Table tblTestComputed CREATE TABLE
tblTestComputed( FirstName VARCHAR(50), LastName
VARCHAR(50) ) Lets insert some data into
it INSERT INTO tblTestComputed(FirstName,
LastName) SELECT 'Tejas', 'Shah' UNION SELECT
'Hiral', 'Shah'
4
So now I run
04/07
SELECT FROM tblTestComputed
I will get output like
output
5
I now require the display name to be something
like "Shah Tejas" or "Shah Hiral". I therefore
created a new column and named it
05/07
ALTER TABLE tblTestComputed ADD FullName AS
(ISNULL(LastName,'') ' ' ISNULL(FirstName,''))
So, now if I run SELECT FROM tblTestComputed
6
I will get output like
06/07
output
7
07/07
Add a computed column called FullName to your
table to combine first and last names, updating
automatically. However, it's essential to note
that computed columns cannot be updated directly
since they are derived from other columns. For
a deeper dive into computed columns and their
applications, click here to learn more.
Write a Comment
User Comments (0)
About PowerShow.com