本文介绍了如何在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

推荐答案



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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:27