本文介绍了传递多个参数时收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我想检索那些非空的值。我写了这个查询,但收到错误。请帮忙。

我的quet是: -



sir i want to retrieve those values which is not null. i have written this query but getting error. please help.
my quet is :-

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);

推荐答案

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

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





通常开发人员不擅长编写SQL。尝试阅读一本好的SQL书。



Usually developers are not good in writing SQLs. Try reading a good book of SQL.


这篇关于传递多个参数时收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:38