Reputation: 211
I am facing an problem to set an default value in sql select query
ex: t1.Employee as EmpDeptName
here i need to set an default value so that it returns always the default value
what i tried t1.Employee as EmpDeptName 'ITdept'
But this fails always telling incorrect syntax
Upvotes: 1
Views: 6331
Reputation: 34054
If you want to SELECT
this value when you call a query,
SELECT 'ITdept' AS EmpDeptName, ...
If you want to use "ITdept" as the default value when the column is empty,
SELECT ISNULL(EmpDeptName, 'ITdept') AS EmpDeptName, ...
If you want to set the column default,
CREATE TABLE t1 (
EmpDeptName <data type> DEFAULT 'ITdept'
);
Upvotes: 6