Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written the following SQL query
select MT.TraAsset, MI.McMake, MI.McModel, MI.McSerial, MT.TraType, MT.TraDate, MT.TraFrom, MT.TraTo,
	F.cFloor_Descriptin,F.nFloor, C.cCmpName 
	from Smt_Mc_McTransfers MT
	left join Smt_Mc_McInformation MI on MI.McAsstNo=MT.TraAsset
	left join SpecFo.dbo.Smt_Floor F on MT.TranFloor=F.nFloor
	left join SpecFo.dbo.Smt_Company C on MT.TranCompanyID=C.nCompanyID
	where (MT.TraApprvBy is null) and (TraApprvDate is null) and MT.TranStatus <> 'Cancel'

There brings no row but one row has to be shown on the basis of above query.
When I change the condition MT.TranStatus is null then the one row shows.
In the database TranStatus =NULL. Thanks in advance.
Posted
Updated 24-Oct-14 0:44am
v2
Comments
Maciej Los 24-Oct-14 6:49am    
There is not SQL issue, but UI problem.
Sumon562 24-Oct-14 6:56am    
I run it in SQL query analyzer. I am using SQL Server 2008. If has anyway please suggest
Abdul Samad KP 24-Oct-14 8:02am    
In the SQL, NULL is treated as special types, so MT. TranStatus <> 'Cancel' will not include rows where MT. TranStatus is null.
To get your desired output, you can use ISNULL (MT. TranStatus,'') <> 'Cancel'

 
Share this answer
 
Comments
vangapally Naveen Kumar 24-Oct-14 8:10am    
good link for beginners..
Maciej Los 24-Oct-14 9:23am    
+5
CPallini 24-Oct-14 9:33am    
Thank you.
Sumon562 wrote:
(...) one row has to be shown on the basis of above query.
When I change the condition MT.TranStatus is null then the one row shows.


Try to change code this way:
SQL
where (MT.TraApprvBy is null) and (TraApprvDate is null) and COALESCE(MT.TranStatus,'') <> 'Cancel'


COALESCE[^] function replaces NULL with 'default' value ;)
 
Share this answer
 
Comments
CPallini 24-Oct-14 9:34am    
Nice, 5.
Maciej Los 24-Oct-14 10:43am    
Thank you, Carlo ;)
MT.TranStatus is NULL so it dont check for that row.If you simply edit the row with something else it will come.You have to insert any status on MT.TranStatus instead of NULL
 
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