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

Add Comment

Computer Programming Articles

1. Custom Snowflake Data Solutions
Author: brainbell10

2. Sketch Digital Design & Product Experience Services
Author: brainbell10

3. Artificial Neural Network Tutorial: Step-by-step Guide To Understanding Neural Networks
Author: Tech Point

4. Sitecore Development Top App Development
Author: brainbell10

5. Learn Mern Stack Online: Tcci Ahmedabad Hub
Author: TCCI - Tririd Computer Coaching Institute

6. Deep Learning Tutorial: Master Deep Learning Basics And Applications Easily
Author: Tech Point

7. Redis Database Development & Integration Services
Author: brainbell10

8. What Is Dynamics 365 Customer Engagement?
Author: davidjohansen

9. Market Forecast: Data Preparation Tools
Author: Umangp

10. Sharepoint Tutorial: Learn Microsoft Sharepoint Basics To Advanced With Examples
Author: Tech Point

11. Is Your Crush Really Crushing On You? Find Out With The Love Tester Online
Author: Katie Heffron

12. Wpf Tutorial For Beginners: Step-by-step Guide To Build Desktop Applications
Author: Tech Point

13. Dynamics 365 Sharepoint Integration Guide
Author: davidjohansen

14. Transparent Managed It: Why Regulated Businesses Are Moving To Productized Service Tiers
Author: ECF Data

15. Quick & Reliable Otdr & Splicing Machine Service In Mumbai
Author: bdean

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