Today I came across scenario where I need to add one computed column. Computed column means we can manipulate one or more column from the same table and we can use this column in queries as regular column. Lets try it: Create One Table: tblTestComputed
Lets insert some data into it:
So now I run:
I will get output like:
Now, I need display name as "Shah Tejas", "Shah Hiral" like that. so what I did is, I added one new column as:
So, now if I run:
So, Output like:
So, I can use this new column "FullName" everywhere to display Full Name. Computed Column is auto updated, means if FirstName OR lastName is changed then content of this column is also changed accordingly One more thing We can not update computed column as it computed by other columns Reference: Tejas Shah (http://www.SQLYoga.com) |
No comments:
Post a Comment