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

Add Comment

Computer Programming Articles

1. Your Complete Bugzilla Tutorial For Managing Software Bugs Efficiently
Author: Tech Point

2. From Beginner To Expert: Ultimate Jira Tutorial For Effective Team Collaboration
Author: Tech Point

3. Top Web Development Institutes In Bhopal: Where Creativity Meets Technology
Author: Kabir Patel

4. The Ultimate Framework Showdown: Which One Will Reign Supreme
Author: Andy

5. Why Your Competitors Are Investing In Custom Software (and You Should Too)
Author: Aimbeat Insights

6. The Hidden Security Risk Of Ssh Keys: Why Manual Linux Access Management Is A Ticking Time Bomb
Author: Tushar Pansare

7. Beyond Ticketing: Using Laravel And N8n To Automate Customer Onboarding Workflows
Author: Andy

8. Top Web Development Institutes In Bhopal: Turning Ideas Into Code
Author: Kabir Patel

9. Software Testing Tutorial: Learn Manual And Automation Testing With Easy Examples
Author: Tech Point

10. Ultimate Yii Framework Tutorial For Building Powerful Php Websites
Author: Tech Point

11. Java Job Support: Real-time Assistance For Developers To Succeed
Author: RKIT Labs Team

12. Unlocking Business Growth With Predictive Analysis
Author: Sakhi Kaya

13. What Is A Distributed Environment In Software Development?
Author: Aimbeat Insights

14. A Multi-tenant Admin Dashboard With Laravel And Next.js
Author: Andy

15. How To Choose The Data Science Training In Bhopal For Your Career Growth
Author: Kabir Patel

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