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

Add Comment

Computer Programming Articles

1. Dynamics 365 Human Resources Capabilities Organizations Managing A Growing Workforce Often Face Challenges Such As Disconnected Hr Systems, Manual Re
Author: brainbell10

2. Market Forecast: Ai Native Networking Platform
Author: Umangp

3. Microsoft Dynamics 365 Sales Module Features
Author: brainbell10

4. Tvos Apps Development Services
Author: davidjohansen

5. Esp Signature Vs Esp Ultimate: A Strategic Breakdown
Author: ECF Data

6. Javascript Tutorial For Students: Step-by-step Learning With Practical Examples
Author: Tech Point

7. Jquery Tutorial: A Complete Guide For Beginners To Advanced Learning
Author: Tech Point

8. Dynamics 365 Implementation Best Practices Guide
Author: brainbell10

9. Sql Server Development Services In Usa
Author: davidjohansen

10. Tableau Consulting & Data Visualization Services
Author: brainbell10

11. Why Startups Should Use Laravel For Ai Product Development
Author: Melisa Hope

12. Custom Snowflake Data Solutions
Author: brainbell10

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

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

15. Sitecore Development Top App Development
Author: brainbell10

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