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

Add Comment

Computer Programming Articles

1. Best Web Development Institutes In Bhopal For Java Coding Classes
Author: Rohan Rajput

2. Master Ai Skills With Industry-leading Certifications
Author: EDCHART

3. The Ultimate Guide To Equipment Rental Software
Author: prestartr

4. The Enduring Importance Of Websites In The Ai Era
Author: Backend Brains

5. Ibm I Security Risks & Best Practices: Protecting Your System In 2025
Author: Siddhant Saxena

6. The Ultimate Guide To Top Web Development Institutes In Bhopal
Author: Rohan Rajput

7. What’s New In Laravel 12 – Features, Updates & Upgrade Guide
Author: espirittechusa

8. Discover The Best App Development Company In Bangalore For Your Next Project
Author: Gaurav Kumar

9. How To Choose The Right Web Development Institute In Bhopal
Author: Rohan Rajput

10. How Digital Publishing Solutions Improve Content Distribution?
Author: tribotz

11. The Evolution And Relevance Of Ibm I (as/400, Iseries) In Modern Business
Author: Siddhant Saxena

12. Ai Software Development Services In Japan: Shaping The Future Of Technology
Author: jagpreet

13. Predictive Maintenance Market Set To Surge To $79.1 Billion By 2032
Author: Rutuja kadam

14. Why Every Business Needs A Custom Mobile App In The Digital Age
Author: Miachael Williams

15. Building A Strong Foundation: Beginner Programming Courses For Young Learners
Author: stem-xpert

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