Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Computed Column - based on IF or CASE

$
0
0

Hi there,

I have a table which has a column say "Code" (type nchar(10)).

I need a column which is computed automatically based on the value in Column "Code". Let say this column is called "Flag".

The condition to be applied is:

IF length of "Code" is > 0, then Flag should be equal to 1, else it should be equal to 0.

Given that Code can have extra spaces before and after, I will prefer to TRIM the code value first and then calculate the LEN.

Can someone please advise on how can I achieve this? I wish to have this computed for each row in the table when inserted or updated. I don't wish to run the "alter table" command as a transact-sql.

thanks,
JT


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>