1

The SP takes the input value ListType_IDs which is a comma separated value of list types.

create procedure test
@ListType_IDs varchar(255) = null
as
declare @IsGetDirectReports bit
declare @IsGetDirectReportsManagers bit
declare @IsGetAllManagers bit
declare @IsGetFullTeamUnderManager bit
--I have to initialize the above flags based on the value of list type IDs

For example, let ListType_IDs=5,6,7

@IsGetDirectReports = 1, if @ListType_IDs has the value 5

@IsGetDirectReportsManagers = 1, if @ListType_IDs has the value 6

@IsGetFullTeamUnderManager = 1, if @ListType_IDs has the value 7

I need to achieve it using simple SQL code. Anybody please help out. Thanks in advance.

Saju
  • 3,201
  • 2
  • 23
  • 28
prabu R
  • 2,099
  • 12
  • 32
  • 41

1 Answers1

2
IF CHARINDEX(',5,' , ',' +@ListType_IDs + ',') > 0
SELECT @IsGetIderctReports = 1

IF CHARINDEX(',6,' , ',' +@ListType_IDs + ',') > 0
SELECT @IsGetDirectReportsManagers = 1

IF CHARINDEX(',7,' , ',' +@ListType_IDs + ',') > 0
SELECT @IsGetFullTeamUnderManager = 1

Is storing a delimited list in a database column really that bad? Now we know.

Community
  • 1
  • 1
Anton Kovalenko
  • 20,999
  • 2
  • 37
  • 69