Click here to Skip to main content
15,912,665 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
My sql query as follows


SQL
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'


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
Posted
Updated 26-Aug-16 0:54am
v2

Hi,

Check this...


SQL IN Operator[^]


Hope this will help you.

Cheers
 
Share this answer
 
See here: How to pass city using for each loop[^] which is probably one of your fellow students asking the same question...
 
Share this answer
 
HI,

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

SQL
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)
 
Share this answer
 
use in operator

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 in ('1','2')
 
Share this answer
 

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