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: 248Word Count: 186See All articles From Author

Add Comment

Computer Programming Articles

1. Learn Programming Efficiently With A Data Structures And Algorithms Tutorial
Author: Tech Point

2. How To Choose The Best Cybersecurity Certification That Offers Top Career Opportunities For You
Author: Lorcam Securities

3. Best C# Tutorial 2026: Master C# For Web And Desktop Development
Author: Tech Point

4. Data Center Cooling Market Growth, Trends & Forecast 2032 | Gmr
Author: Caitan Cruz

5. Ceh, Oscp, Or Comptia Security+: Which Cybersecurity Certification Is Best For You?
Author: Lorcam Securities

6. Microsoft Power Automate Workflow Automation Services
Author: brainbell10

7. Comprehensive Salesforce Tutorial: Learn Sales Cloud, Service Cloud, And Architecture
Author: Tech Point

8. Why Call Centers Prefer Renting Pcs Instead Of Buying Them
Author: Harsh

9. Macbook Repairs Adelaide – Professional & Reliable Service By Fix Laptops
Author: Fix Laptops

10. The Complete Ccie Security Lab Practice Companion
Author: ccielabpass

11. Web3 Blockchain Experts Jaipur
Author: Lalit Kumar Gupta

12. Flutter Tutorial For Beginners: Step-by-step Guide To Mobile App Development
Author: Tech Point

13. Python Cgi Programming Tutorial: Learn Server-side Python Step By Step
Author: Tech Point

14. Incomplete Access Reviews: A Growing Enterprise Security Risk And How To Resolve It
Author: Tushar Pansare

15. Typescript Tutorial: Learn Typescript From Basics To Advanced
Author: Tech Point

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