ALL >> Computer-Programming >> View Article
Sqlyoga: Adding Computed Columns In Sql Server

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.
Add Comment
Computer Programming Articles
1. Career Opportunities After Completing The Best Business Analytics Courses In BhopalAuthor: Rohan Rajput
2. Network Security Essentials For It Professionals
Author: TCCI - Tririd Computer Coaching Institute
3. Emerging Programming Languages To Watch In 2026
Author: TCCI - Tririd Computer Coaching Institute
4. Python Scipy Tutorial: Simplifying Scientific And Technical Computing
Author: Tech Point
5. Is Scalatra The Right Fit For Your Web Framework Needs? Why You Should Hire Scalatra Developers Today
Author: Stellanova GlobalTech
6. Why Office 365 Is The Smartest Choice For Modern Businesses
Author: michellumb44
7. Why Choose Bhopal For The Best Business Analytics Courses? A Student’s Guide
Author: Rohan Rajput
8. Top Devops Certification Course In Chennai | Industry-ready Skills
Author: login360
9. Beyond The Code: Key Considerations When You Hire Software Developers For Skill And Cultural Alignment
Author: Stellanova GlobalTech
10. How Cism Certification Can Boost Your Cybersecurity Career
Author: Johnny
11. Which Is The Best Programming Language To Build A Mobile App?
Author: DianApps
12. Explore Career Growth With The Best Business Analytics Courses In Bhopal
Author: Rohan Rajput
13. From Zero To Hero: Python Pygame Tutorial For Aspiring Game Developers
Author: Tech Point
14. Beginner’s Python Pytorch Tutorial: Start Your Ai Journey Today
Author: Tech Point
15. Top 10 Cloud Security Threats And How To Prevent Them
Author: GIGABITTechnologies