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. How To Optimize Your Web App Development Costs?Author: brainbell10
2. Google Cloud Data Engineer Course | Gcp Training & Certification
Author: ravinder
3. Less Tutorial: A Complete Guide For Beginners To Advanced Learning
Author: Tech Point
4. Complete Sass Tutorial For Beginners: Master Modern Css Preprocessing
Author: Tech Point
5. Factors For Choosing Restaurant App Development For Your Business
Author: brainbell10
6. How Custom Web Application Development Improves Business Efficiency
Author: Rudram Technology Solutions
7. Flat Design Or Material Design – Which One To Prefer?
Author: brainbell10
8. How To Use Linkedin Market Your Business?
Author: brainbell10
9. 5 Reasons To Choose Business Central
Author: Modern businesses need a connected ERP solution th
10. How To Create A Wordpress Lms Website For Your Employees?
Author: brainbell10
11. Why Every Business Should Conduct Security Awareness Assessments Regularly
Author: Sam Vohra
12. Why Invest In Professional E-commerce Website Development? | Complete Guide For Growing Businesses
Author: Rudram Technology Solutions
13. How To Use Motion Design To Make App Experience Interesting?
Author: brainbell10
14. How To Prototype A Mobile App?
Author: brainbell10
15. Sql Server Tutorial – Learn Database Management With Step-by-step Examples
Author: Tech Point






