Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Null value replace "Absent" how?

this is my query

some time only in out value is null , so null value replace to "Absent"

SQL
select  distinct
E.USERID as [رقم الموظف],
U.User_FirstName+ ' ' + U.User_LastName as [اسم الموظف] ,
CONVERT(Date,LOCALTIMESTAMP) as [تاريخ العمل],
(select min(Convert (TIME,LOCALTIMESTAMP))
from access_event_logs As MINCE
where CAST(MINCE.LOCALTIMESTAMP as DATE)=CAST(E.LOCALTIMESTAMP As DATE) AND MINCE.EVENTID ='In' and MINCE.USERID=E.USERID) As [وقت الدخول],
(select max(Convert (TIME,LOCALTIMESTAMP))
from access_event_logs As MAXCE
where CAST(MAXCE.LOCALTIMESTAMP as DATE)=CAST(E.LOCALTIMESTAMP As DATE) AND MAXCE.EVENTID ='Out' and MAXCE.USERID=E.USERID) As [وقت الخروج]
from access_event_logs As E Inner join access_user as U on E.USERID = U.User_ID where Convert(date,LOCALTIMESTAMP) between '14/May/2014' And '14/May/2014'
Posted

use case statement:

SQL
select case when column1 is null then 'Absent' else  column1 end from table1
 
Share this answer
 
Consider using ISNULL or COALESCE see msdn reference[^] which discusses the merits of isnull, coalesce and case.

e.g. if 'Out' is the default...
AND ISNULL(MAXCE.EVENTID, 'Absent') ='Out' 
or
AND COALESCE(MAXCE.EVENTID, 'Absent') ='Out' 
 
Share this answer
 
v2
Comments
akhil.krish 20-May-14 9:17am    
hi chill thanks for rply

not working both......
CHill60 20-May-14 9:32am    
They were only supposed to be examples. I've updated my solution
akhil.krish 20-May-14 9:57am    
HI CHILL,
update my code.. after update result below like this

http://tinypic.com/view.php?pic=e9yy39&s=8#.U3te7fmSyYM
akhil.krish 20-May-14 11:06am    
did u see my image......
CHill60 20-May-14 11:42am    
Once I got past the adverts! It might be easier if you explain what you are trying to do ... I suspect a PIVOT might be better for you
You can use ISNULL built in function of sql server .... :)
and the syntax is..
SQL
select ISNULL(columnName,'What ever would you like to replace') from TableName


Now, You can modified it according to your need.. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900