Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have a View in SQL Server, dynamically add one column with default value! How Can I define a default Value Column in View?
Posted
Comments
ChauhanAjay 20-Aug-14 8:10am    
Will the dynamic column be a hard coded column?

1 solution

If the column you need a default for requires a value when NULL, use the ISNULL function:

SELECT a, b, ISNULL(c, 'DEFAULT') AS c FROM xyz

If you need the default when the field is blank, has some sentinel value or anything else use the CASE/END construct (this is a little more complex, so you should read the documentation, but something like:

SELECT a, b, CASE c WHEN NULL THEN 'Null' WHEN '' THEN 'Blank' ELSE c END AS c FROM xyz
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900