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

Add Comment

Computer Programming Articles

1. Effortlessly Convert Sale Orders To Purchase Orders In Odoo
Author: CodersFort

2. Best Software Development Comapny In Wayanad, Kerala, India
Author: TRUSTWAVES

3. How To Spot Red Flags In Invoices And Stop Fraud Instantly?
Author: Invoice Temple

4. Top Ai Development Company In Delhi: Leading Artificial Intelligence Services By Doubleklickdesign
Author: Prince

5. What Are The Best Coding Institutes In Bhopal?
Author: Shankar Singh

6. Innovating Blockchain Strategies With Mev Bot Technology
Author: aanaethan

7. How To Choose The Right Coding Institute In Bhopal
Author: Shankar Singh

8. Streamline Your Finances With The Best Bookkeeping Software In Zambia
Author: Doris Rose

9. Maximizing Ebay Success With Maropost/neto Partnerships
Author: rachelvander

10. The Rise Of Ai In Modern Gaming
Author: Saira

11. Enhancing Business Efficiency With Entrust Network: Singapore’s Premier It Solutions Partner
Author: Entrust Network Services

12. Ai And Ml Training: Empowering Your Career With Infograins Tcs
Author: Infograins tcs

13. How To Evaluate Coding Institutes In Bhopal?
Author: Shankar Singh

14. Revolutionizing Delivery Services With Application Development
Author: basheer ansari shaik

15. How Google Cloud Platform Aids Businesses And Keeps Its Data Safe?
Author: Stuart

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