How to write computed column with string using of auto incremented identity like
Usercode001
Usercode002
Usercode003
Usercode004
Usercode005
in SQL Server
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kunal PatelPosted Mar 31, 2016, 5:09 AM
(
ID INT IDENTITY(1, 1)
NOT NULL ,
UserCode VARCHAR(20) ,
ComputedValue VARCHAR(50)
)
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @lastInsertedid INT
SET @lastInsertedid = ( SELECT IDENT_CURRENT('Products')
)
UPDATE Products
SET ComputedValue = UserCode
+ CONVERT(VARCHAR(50), @lastInsertedid)
WHERE ID = @lastInsertedid
END;
( UserCode, ComputedValue )
VALUES ( 'UserCode','')
FROM [Products]
Pramod ThakurPosted Mar 30, 2016, 10:12 PM
chenna gadicherlaPosted Mar 30, 2016, 9:15 AM
Pramod ThakurPosted Mar 30, 2016, 7:46 AM