123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computer-Programming >> View Article

Sqlyoga: Adding Computed Columns In Sql Server

Profile Picture
By Author: sqlyoga
Total Articles: 4
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

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.

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'
So now I run:
SELECT * FROM tblTestComputed
I will get output like:
Output
I now require the display name to be something like “Shah Tejas” or “Shah Hiral”. I therefore created a new column and named it:
ALTER TABLE tblTestComputed
ADD FullName AS (ISNULL(LastName,'') + ' ' + ISNULL(FirstName,''))
So, now if I run:
SELECT * FROM tblTestComputed
So, Output like:
Output
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. Join SQLYoga to boost your SQL and database skills with tutorials, articles, and expert tips. Be part of a growing community of learners.

Total Views: 321Word Count: 186See All articles From Author

Add Comment

Computer Programming Articles

1. Jenkins Tutorial For Beginners: Learn Continuous Integration Step By Step
Author: Tech Point

2. Docker Tutorial With Practical Examples To Master Containerization
Author: Tech Point

3. Why Website Development Is Essential For Digital Success
Author: Rudram Technology Solutions

4. Dynamics 365 Business Central Cloud
Author: brainbell10

5. Sap Successfactors Access Management: How To Close The Jml Gap Across Every Connected System
Author: Mansoor Alam

6. Strategies For Crm Sales Productivity
Author: brainbell10

7. Understanding The Latest Trends In App Development
Author: Levin Charles

8. Best Cloud Databases
Author: brainbell10

9. Best Online Learning Platforms
Author: brainbell10

10. Software Training Institute In Trichy – Build A Successful It Career
Author: massclick

11. Enhancing Automation And Quality Control With Ai-powered Vision Technologies
Author: John Smith

12. How To Manage Challenges Of Long-term Projects?
Author: brainbell10

13. How To Launch Mobile App Successfully?
Author: brainbell10

14. R Programming Tutorial: Step-by-step Guide To Master R Programming
Author: Tech Point

15. Android Tutorial: Everything You Need To Know To Start Android Development
Author: Tech Point

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: