比如数据库有2列 userid username
想查询这2列 其中 如果username为null 则用'-'代替select case username when () then '-' else username from table()中的要怎么填? 我试了好几种方式都不对求教~~~~~~
想查询这2列 其中 如果username为null 则用'-'代替select case username when () then '-' else username from table()中的要怎么填? 我试了好几种方式都不对求教~~~~~~
select case when username is null then '-' else username end from table
from tb
(
userid INT IDENTITY,
username VARCHAR(10)
)
INSERT #temp
SELECT 'a' UNION ALL SELECT NULL
go
--SQL:
SELECT
userid,
username = CASE WHEN username IS NULL THEN '-' ELSE username END
FROM #temp
/*
1 a
2 -
*/
from table
case when username is null then '-' else username end
from
table
select
isnull(username,'-')
from
table
select
userid,
case when username IS null
then '-'
else username
end
from tb
select
userid,
ISNULL(username,'-')
from tb
userid,
case when username IS null
then '-'
else username
end
from tb
select
userid,
ISNULL(username,'-')
from tb