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
精彩评论