Greetings to all, I would like to know if any of you have used any method that allows you to store a numerical string separated by commas and then save it in a variable to be used later.
In the following example, what I am trying to do is that the variable @UnitsysId stores the entire string of the numbers, each comma separation corresponds to the id of each catalog of a record. At the time of filtering by the variable does not accept it. Does anyone know how to do this and if it is possible to do so?
declare @unitsysid varchar(max)
set @unitsysid = 120529170,120520370,120536170,120535270,120524770,159254670,108139370,104620670,165324570
select v.UnitSysId, v.VehicleId as VehicleFleetVehicleID,a.VehicleId as VehicleSVRVehicleId,p.SharedVehicleId as VehicleSharedId
from Fleet..Vehicles v with (nolock)
join AVLStatic..Vehicles a with (nolock) on v.UnitSysId=a.RMUId
join PAI..PAIVehicleShared p with (nolock) on v.VehicleId=p.FleetVehicleId
where v.UnitSysId in (@unitsysid) order by v.VehicleId asc
It should be mentioned that if I enter the data directly in the query instead of the variable, it shows me without any problem.
select v.UnitSysId, v.VehicleId as VehicleFleetVehicleID,a.VehicleId as VehicleSVRVehicleId,p.SharedVehicleId as VehicleSharedId
from Fleet..Vehicles v with (nolock)
join AVLStatic..Vehicles a with (nolock) on v.UnitSysId=a.RMUId
join PAI..PAIVehicleShared p with (nolock) on v.VehicleId=p.FleetVehicleId
where v.UnitSysId in (120529170,120520370,120536170,120535270,120524770,159254670,108139370,104620670,165324570) order by v.VehicleId asc
UnitSysId VehicleFleetVehicleID VehicleSVRVehicleId VehicleSharedId
120520370 24803 35588 20119
120536170 24809 35594 20125
120535270 24811 35596 20127
120524770 24813 35598 20129
120529170 24818 35603 20134
159254670 31608 41933 27116
104620670 50398 44270 29828
108139370 50413 44285 29844
165324570 52041 45819 33485
Thank you.