Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
i have values Employee has

Declare emp varchar(10)
set emp ='harsh,suresh, mohan'

select * form Emp where name in (emp)

What I have tried:

Declare emp varchar(10)
set emp ='harsh,suresh, mohan'

select * form Emp where name in (replace(emp, ',','',''))
Posted
Updated 24-Jul-18 18:53pm
Comments
Naga Sindhura 25-Jul-18 9:48am    
How data in name field stored in?
for 'harsh,suresh, mohan' condition - three different records- one for harsh, other for suresh, And, one more for mohan.
/Or harshsureshmohan /or something else
Please post your comment?

 
Share this answer
 
declare @emp VARCHAR(10)
set @emp= 'harsh,suresh,mohan'
select @emp
SELECT REPLACE(@emp, ',','','')
 
Share this answer
 
v2
Comments
CHill60 25-Jul-18 9:14am    
This generates a syntax error. Please check your code before posting or state that it is untested
Naga Sindhura 25-Jul-18 9:44am    
may be her intention is SELECT REPLACE(@emp, ',','') not SELECT REPLACE(@emp, ',','','')
CHill60 25-Jul-18 10:38am    
And then I would comment that it just removes the commas and does not replace them with single quotes as the title clearly stated. I would also then comment that a varchar(10) is not long enough for the string 'harsh,suresh,mohan' (18 characters), so my comment "Please check your code before posting or state that is is untested" still stands
Naga Sindhura 26-Jul-18 7:29am    
Agreed.. But small correction ...varchar(10) mentioned in the Problem Statement itself.. I know it is wrong as you mention earlier..
declare @emp VARCHAR(100)
set @emp= 'harsh,suresh,mohan'
select @emp
SELECT REPLACE(@emp, ',',' ')
 
Share this answer
 
Comments
CHill60 25-Jul-18 9:15am    
This replaces the commas with a space. The OP wanted to replace them with single quotes - as the title clearly states

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