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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kunal PatelRank #1,359 · 1.2K reputationPosted Mar 31, 2016, 1:09 AM EDT
(
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 ThakurRank #400 · 6.3K reputationPosted Mar 30, 2016, 3:46 AM EDT
chenna gadicherla25 reputationPosted Mar 30, 2016, 5:15 AM EDT
Pramod ThakurRank #400 · 6.3K reputationPosted Mar 30, 2016, 6:12 PM EDT