如何在SQL查询中传递多个城市id [英] How to pass mutiple city id in SQL query

查看:182
本文介绍了如何在SQL查询中传递多个城市id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的sql查询如下





Hi,
My sql query as follows


select DISTINCT date_TripDate AS TripDate,traveltype.varchar_TravelTypeCode AS TripType,contactss.Value as Mobilenumber,from [OneC_988].[dbo].[988_Details_VehicleRequest] request join [OneC_988].[dbo].[988_Details_VehicleTrip] trip on request.int_VehicleRequestID=trip.int_VehicleRequestID
and int_CityID ='1'





我尝试过:



当我按如下方式运行上述查询输出时



Tripdate TripType Mobilenumber int_CityID



26th aug 16 IN 9878778878 1

26th aug 16 IN 9949949990 1

26th aug 16 IN 9878778878 1







i想要在上面的sql查询中传递INT_CityID 1和2以获得如下输出



Tripdate TripType Mobilenumber int_CityID



26th aug 16 IN 9878778878 1

26th aug 16 IN 9949949990 1

26th aug 16 IN 9878778878 1



28th aug 16 IN 9878778878 2

28th aug 16 IN 9949949990 2

28th aug 16 IN 9878778878 2



What I have tried:

When i run the above query output as follows

Tripdate TripType Mobilenumber int_CityID

26th aug 16 IN 9878778878 1
26th aug 16 IN 9949949990 1
26th aug 16 IN 9878778878 1



i want to pass both INT_CityID 1 and 2 in the above sql query to get output as follows

Tripdate TripType Mobilenumber int_CityID

26th aug 16 IN 9878778878 1
26th aug 16 IN 9949949990 1
26th aug 16 IN 9878778878 1

28th aug 16 IN 9878778878 2
28th aug 16 IN 9949949990 2
28th aug 16 IN 9878778878 2

推荐答案

您好,



查看此...





SQL IN Operator [ ^ ]





希望这会对你有所帮助。



干杯
Hi,

Check this...


SQL IN Operator[^]


Hope this will help you.

Cheers


见这里:如何为每个循环使用城市 [ ^ ]这可能是其中之一你的同学问同样的问题...
See here: How to pass city using for each loop[^] which is probably one of your fellow students asking the same question...


HI,



如果城市id正在以字符串形式分割数据并保存到一个动态表格中并作为参数显示





If the city id's are comming as string split the data and saved in to one dynamic table and pasing as parameter

Declare @TempSource as table (Sno int identity(1,1),Inputvalues varchar(50))
insert into @TempSource(Inputvalues) values('5')
insert into @TempSource(Inputvalues) values('4')
insert into @TempSource(Inputvalues) values('6')


Declare @TempData as table (Sno int identity(1,1),CityName varchar(50),CityID varchar(50))
insert into @TempData(CityName,CityID) values('City1','1')
insert into @TempData(CityName,CityID) values('City2','2')
insert into @TempData(CityName,CityID) values('City4','4')
insert into @TempData(CityName,CityID) values('City6','6')

select * from @TempData
where CityID in (select Inputvalues from @TempSource)


这篇关于如何在SQL查询中传递多个城市id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆