Error Msg 128 The name is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted
Lets see how to avoid this error:
Error Msg 128 The name is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted
When would we see this error?
When we try to add a column as default value for another column.
Create table tblSalesInfo
(
custId int,
SaleDate datetime,
IntimateDate datetime default (saledate - 10)
)
Go
Saledate is a column which we are trying to use it within default value assignment for IntimateDate which is not valid.
Workaround:
Create table tblSalesInfo
(
custId int,
SaleDate datetime,
IntimateDate as (saledate - 10)
)
Testing:
Insert into tblSalesInfo (custid, saledate) values (1, getdate())
Go
Select * from tblSalesInfo
Go
Comments