ALL >> Computer-Programming >> View Article
Sqlyoga: Adding Computed Columns In Sql Server

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.
Add Comment
Computer Programming Articles
1. The Dynamic Landscape Of Advertising Agencies In Indonesia: A Hub For Creativity And InnovationAuthor: milestone
2. 10 Advantages Of Building A Career In Full Stack Java Development In Bhopal
Author: Rohan Rajput
3. Top Mobile App Development Company In Canada: Comprehensive Solutions For Your Business
Author: iTechnolabs
4. Democratizing Development: The Rise Of Low-code And No-code Platforms
Author: Techeunoia International
5. Amazon Product Listing Services: Boost Your Sales With Optimized Listings
Author: rachelvandereg
6. Best Accounting Software 2025 In Zambia: Tips And Best Practices
Author: Doris oseR
7. Aryabhata And The Birth Of Zero: A Legacy That Powers Modern Ai And Machine Learning
Author: Pydun Technology Private Limited
8. Top 5 Video Conferencing Solutions Of 2025
Author: Ben Gross
9. Best Practices For Building High-performance React Native Apps
Author: William
10. Top 10 Reasons To Pursue Full Stack Java Development In India
Author: Rohan Rajput
11. Transform Your Digital Presence With Expert Drupal Development
Author: manish
12. We Provide It Solutions That Help You Succeed
Author: We provide IT solutions that help you succeed
13. What Makes A Full Stack Developer Stand Out In 2025?
Author: Shrushti Gurav
14. Effortlessly Convert Sale Orders To Purchase Orders In Odoo
Author: CodersFort
15. Best Software Development Comapny In Wayanad, Kerala, India
Author: TRUSTWAVES