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

Add Comment

Computer Programming Articles

1. Jagdish Mahapatra Md Apj Google Cloud Security On Securing The Cloud & Leading With Purpose
Author: Orson Amiri

2. Enough Is Enough: How To Hire The One Web Development Company In Calgary That Gets Roi
Author: It Master

3. Appium Tutorial: Learn How To Test Mobile Applications Like A Pro
Author: Tech Point

4. Why Software Maintenance Is More Important Than Development Itself
Author: Aimbeat Insights

5. How Load Balancing Routers In India Ensure Stable, Fast Connectivity
Author: shivani

6. Top Features To Include In A Modern Crypto Exchange Platform
Author: Lily Rose

7. Feature-rich, Future-ready: Why Businesses Trust Logitrac360 To Stay Ahead
Author: LogiTrac360

8. Top Web Development Institutes In Bhopal For Career-driven Learners
Author: Kabir Patel

9. Why Progressive Web Apps (pwas) Are The Future Of Mobile Experiences
Author: Aimbeat Insights

10. Unlocking Community Gold: How Reddalyze Makes Subreddit Research & Marketing Tools Work For You
Author: Taylor

11. Top Web Development Institutes In Bhopal That Shape Future Developers
Author: Kabir Patel

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

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

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

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

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