Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 charindex

Author  Topic 

nord
Posting Yak Master

126 Posts

Posted - 2013-10-30 : 13:18:04
Hi,
I have 2 fields in different tables,I need to find strim=ng in another string for example:
column1 column 2
'10' '10','11','12','13'
'1','2','3' '1','2','3','4','5'
Thanks for help

nord
Posting Yak Master

126 Posts

Posted - 2013-10-30 : 13:21:42
Hi,
I have 2 fields in different tables,I need to find strim=ng in another string for example:
column1 column 2
'10' '10','11','12','13'
'1','2','3' '1','2','3','4','5'
Thanks for help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-30 : 13:24:49
do you mean this?

SELECT *
FROM Table
WHERE ',' + column2 + ',' LIKE '%,' + column1 + ',%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

nord
Posting Yak Master

126 Posts

Posted - 2013-10-30 : 13:39:18
Yes,thanks
how I can do it with charindex?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-30 : 13:43:25
why? whats the issue with provided suggestion?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-30 : 13:46:09
you need PATINDEX and not CHARINDEX as its pattern search

SELECT *
FROM Table
WHERE PATINDEX('%,' + column1 + ',%',',' + column2 + ',')>0


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

nord
Posting Yak Master

126 Posts

Posted - 2013-10-30 : 13:49:28
Thanks
Go to Top of Page
   

- Advertisement -