0
CREATE TABLE #temp
(FName    VARCHAR(10),
 LName    VARCHAR(10),
 FullName VARCHAR(21) DEFAULT(FName+' '+LName)
);

When I try the above statement I am getting the following error. Is there any workaround available for this?

Msg 128, Level 15, State 1, Line 1 The name "FName" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.

2
  • 3
    Either you want FullName to always be FName + ' ' + LName, then make it a computed column. Or you only want to set an initial value, then use a before-insert trigger. Commented Nov 20, 2017 at 7:10
  • Thanks for providing workaround. Commented Nov 20, 2017 at 7:57

1 Answer 1

3

If you don't need to edit it you can use a calculated column

CREATE TABLE #temp
(FName    VARCHAR(10),
 LName    VARCHAR(10),
 FullName AS (FName+' '+LName)
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.