Click here to Skip to main content
16,010,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i want to retrieve those values which is not null. i have written this query but getting error. please help.
my quet is :-

C#
SqlCommand sqlcmd = new SqlCommand("Select wifi,restaurant,Transport,Exercise,Business,FoodBar,Casino,Swimming,Shopping,Wheelchair from hotel_facilities where wifi,restaurant,Transport,Exercise,Business,FoodBar,Casino,Swimming,Shopping,Wheelchair is Not null in(Select hotel_name from hotel_Addrecord where hotel_id='" + getid + "' )", sqlcon);
Posted
Updated 20-May-15 19:55pm
v2
Comments
Mehdi Gholam 21-May-15 2:03am    
"getting error" is not very helpful information, post the error message.

1 solution

Its pretty hard to guess/read your mind with very limited/ambiguous information. I am trying to propose a solution which may need some bit of tweaking. You need to modify your sql in a way similar to below sql. You also need to avoid concatenating strings which are open to sql injection attacks.

SQL
Select	hotel_facilities.hotel_id, wifi,restaurant,Transport,Exercise,Business,FoodBar,Casino,Swimming,Shopping,Wheelchair 
from	hotel_facilities
		INNER JOIN hotel_Addrecord on hotel_facilities.hotel_id = hotel_Addrecord.hotel_id
where	hotel_facilities.hotel_id = {some_id} AND
		(wifi + restaurant + Transport + Exercise+Business+FoodBar+Casino+Swimming+Shopping+Wheelchair) is not null


Below is a running example

SQL
Select	hotel_facilities.hotel_id, wifi,restaurant,Transport,Exercise,Business,FoodBar,Casino,Swimming,Shopping,Wheelchair
from	
(
		select 1 as hotel_id, 
			   'Yes' as wifi,
			   'Yes' as restaurant,
			   'Yes' as Transport,
			   'Yes' as Exercise,
			   'Yes' as Business,
			   'Yes' as FoodBar,
			   'Yes' as Casino,
			   'Yes' as Swimming,
			   'Yes' as Shopping,
			   'Yes' as Wheelchair 
	    UNION ALL
		select 2 as hotel_id, 
			   'Yes' as wifi,
			   'Yes' as restaurant,
			   'Yes' as Transport,
			   'No' as Exercise,
			   'Yes' as Business,
			   'Yes' as FoodBar,
			   NULL as Casino,
			   'Yes' as Swimming,
			   'Yes' as Shopping,
			   'Yes' as Wheelchair 
	    
) hotel_facilities
		INNER JOIN 
		(
			select 1 as hotel_id
			UNION ALL 
			select 2 as hotel_id
		)hotel_Addrecord on hotel_facilities.hotel_id = hotel_Addrecord.hotel_id
where	hotel_facilities.hotel_id = 1 AND
		(wifi + restaurant + Transport + Exercise+Business+FoodBar+Casino+Swimming+Shopping+Wheelchair) is not null


Usually developers are not good in writing SQLs. Try reading a good book of SQL.
 
Share this answer
 
v2
Comments
Rajiv.net40 21-May-15 7:41am    
not working your code sir
_Asif_ 21-May-15 7:44am    
how you checked it?

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