Create Procedure Sp_test
@ChannelID nvarchar(100),
@DealerID nvarchar(100),
@AreaID nvarchar(100),
@ZoneID nvarchar(100),
@TrainingID nvarchar(100) ,
@sessionid nvarchar(100),
@RoleID nvarchar(100)
as
declare @str varchar(1000)
Begin
set @str= 'select distinct z1.Zone,A1.AreaName as AO ,D1.ID,D1.Code as dealerCode,D1.Name as DealerName,MPE1.ManPowerId,MP1.EmployeeCode,
(MP1.FirstName + '''' + MP1.LastName) as Name,
(select SkillName from dbo.Mas_Skills where ID=MPE1.SkillId) as empRole,MPT.TrainingId,MT.Code,MPT.TrainingCompletionDate
from DealerChannelMapping DM1,Dealer D1 ,Mas_Zone Z1,Mas_Area A1,
dbo.ManPowerExperience MPE1,
ManPower MP1 ,ManPowerTraining MPT,Mas_Training MT ,Mas_Skills MS
where D1.ID=DM1.DealerID and Z1.ID=A1.ZoneId and MS.ID=MPE1.SkillId
and MPE1.DealerID=D1.ID and MPT.TrainingId=MT.ID and MS.IsActive=1 and MPE1.IsActive=1
and D1.IsActive=1 and MT.IsActive=1 and MPT.IsActive=1 and DM1.IsActive=1 and MP1.IsActive=1
and Z1.IsActive=1 and A1.IsActive=1 and
MPE1.ManpowerId=MP1.ID '
if (@ChannelID <> 0)
begin
set @str= @str + ' and DM1.ChannelID='+@ChannelID
end
if (@DealerID <> 0)
begin
set @str= @str + ' and DM1.DealerID='+@DealerID
end
if (@ZoneID <> 0)
begin
set @str= @str + ' and Z1.ID='+@ZoneID
end
if (@AreaID <> 0)
begin
set @str= @str + ' and A1.ID='+@AreaID
end
if (@RoleID <> 0)
begin
set @str= @str + ' and MPE1.SkillId='+@RoleID
end
if (@TrainingID <> 0)
begin
set @str= @str + ' and MPT.TrainingId in (select TrainingId from DumyTrainingReadiness where sessionid = '''+@sessionid
set @str= @str + ''')'
end
exec (@str)
end
No comments:
Post a Comment