0

Here i have a table 'tbllead' which is having column'leademployees' which contains the values such as

(450,449,451)- row1 
(450,449,451)-row 2
(455,449,454,451)- row3
(450,449,451)-row 4 
(450)-row5 )

then how to get the rows if my query is

select *
from TblLead
where LeadEmployees=451

enter image description here

The desired result should be... row 25,26,27,28,29,31,32,33,34,35

1
  • 1
    Never, ever store data as comma separated items. It will only cause you lots of trouble. Commented Nov 17, 2017 at 12:05

2 Answers 2

2

You should fix your data model. Storing lists of numbers as strings SQL is wrong:

  • Values should have the right data type
  • Foreign key relationships should be properly defined
  • SQL has poor string functions
  • Such queries cannot be optimized very well

Sometimes, you are stuck with someone else's really bad design decisions. Here is one thing you can use like:

where ',' + cast(LeadEmployees as varchar(255)) + ',' like '%,' + '451' + ',%'
Sign up to request clarification or add additional context in comments.

Comments

0

It is very common scenerio where employee manage employees erds easily available. May be this is helpfull enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.