hi Friends i have small doubt in sql server
how to write case statement if field exist then return same field other wise create field.that means i show table data like
id,name,sal
1 ,rav ,300
2,ven ,900
output
id,name,sal,deptno
1,rav ,300 , null
2,ven ,900 ,null
i tried like select id,name,sal,'null' as deptno from table.
but its not good way because of some table dont have id fields and name fields,and some table having 100 fields so here we need check that field exist or not which ever required field not there then create that field othere wise return same field.
can any body tell me how to write case statement in sql server