简体   繁体   中英

Sql query with default value

I have a select Query in employee table. I need to make sure that column value(empaddress) always pass an empty value in select query:

SELECT 
    empname,
    empaddress,
    empDeptid  
FROM 
    empiD=3

I know that empaddress can contain any value like Null or data. But in the result set it should always be blank

You could do something like this:

SELECT 
    empname,
    "" as empaddress,
    empDeptid   
FROM 
   empiD=3

Unless I am missing something here that would return a blank string in place of the empaddress

Try something like this:

SELECT 
    empname,
    null as empaddress,
    empDeptid   
FROM 
    empiD=3;
SELECT empname, Isnull(empaddress,'')empaddress, empDeptid FROM empiD=3

Simply add ISNULL function with '' and it will appear blank:

SELECT 
    empname,
    ISNULL(empaddress,'') AS EmpAddress,
    empDeptid  
FROM 
    empiD=3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM