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

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

问题描述

我的sql查询如下



选择DISTINCT date_TripDate AS TripDate,traveltype.varchar_TravelTypeCode AS TripType,contactss.Value as Mobilenumber,来自[OneC_988]。[dbo] 。[988_Details_VehicleRequest]请求加入[OneC_988]。[dbo]。[988_Details_VehicleTrip] trip on request.int_VehicleRequestID = trip.int_VehicleRequestID

和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



我尝试了什么:



如何在sql查询中传递多个城市id

解决方案

至少有两种方式:

1)使用

 ...  WHERE  ... (int_CityID =  1   OR  int_CityID =  2 



2)使用 IN

 ...  WHERE  ... 和 int_CityID  IN  1  2 


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'

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

What I have tried:

how to pass mutiple city id in sql query

解决方案

There at least 2 way :
1) using or

... WHERE ... and (int_CityID = 1 OR int_CityID = 2)


2) using IN :

... WHERE ... and int_CityID IN (1,2)


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

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