I just Started working with SQL Server and I want to set one column of my table based on another column(automatically and both columns are in a same table). I’ve wrote a function like this:
ALTER FUNCTION [dbo].[FloorNameConvertor]
(
@Number int
)
RETURNS nchar(10)
AS
BEGIN
RETURN
( CASE
WHEN @Number/100=1 THEN 'x'
WHEN @Number/100=2 THEN 'y'
ELSE 'w'
END
)
END
and I use it in default value of my column properties. I have problem to send a value of the cell as a parameter ( I can’t select one cell )?
Thanks
You cannot use other column names in default constraints. You can work it around with
INSTEAD OF INSERTtrigger or use computed column (not persisted though).