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. Kivy Tutorial: A Complete Guide To Python Gui DevelopmentAuthor: Tech Point
2. How To Choose The Right Java Software Development Company For Your Business
Author: codemech solutions
3. Jupyter Notebook Tutorial: A Complete Guide For Beginners
Author: Tech Point
4. Pyspark Tutorial: Learn Python Based Big Data Processing Step By Step
Author: Tech Point
5. How To Hire Python Developer?
Author: davidjohansen
6. Cto (cipoletti Technology Organization)
Author: Steve Chase
7. Linq Tutorial In C#: Learn Language Integrated Query Step By Step
Author: Tech Point
8. Digital Marketing Company In Delhi: Helping Businesses Build A Strong Online Presence
Author: Code Sparrow
9. Connected Living And Digital Transformation With Custom Iot And Home Automation Solutions
Author: John Smith
10. Why Businesses Need Custom Conversational Ai Chatbots
Author: Fasturex
11. Cmmc 2.0 Compliance Consulting For Defense Contractors
Author: CMMC
12. Building A Stronger Cybersecurity Culture With Security Awareness Programs
Author: Sam Vohra
13. Kotlin Tutorial: A Complete Guide To Kotlin Programming For Beginners
Author: Tech Point
14. Dart Tutorial: Learn Dart Programming Concepts From Basics To Advanced
Author: Tech Point
15. Checklist: What To Consider Before You Hire Software Developers In India
Author: Nevil Martin






