开发者

make blank row appear 0 in ms sql

I have a table containing Remarks as a column. Now i have to dis开发者_开发问答play the data inside remarks as 0 if the row is blank i.e empty but not Null. Please give me a query that will solve my problem in MS SQL server 2005.


Use SELECT ... CASE

SELECT remarksDisplay = CASE remarks WHEN '' THEN '0' ELSE remarks END
FROM tableName;


use a case statement in your SQL i.e

select (case when Remarks = '' then '0' else Remarks end) as Remarks from RemarksTable

You can further extend this to handle null values too if you want i.e

select (case when isnull(Remarks, '') = '' then '0' else Remarks end) as Remarks from RemarksTable


SELECT 
case column1
when '' then 'unknown'  /*empty*/
when ' ' then 'unknown' /*empty with space*/
end

FROM table
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜