SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 charindex
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nord
Posting Yak Master

126 Posts

Posted - 10/30/2013 :  13:18:04  Show Profile  Reply with Quote
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 - 10/30/2013 :  13:21:42  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 10/30/2013 :  13:24:49  Show Profile  Reply with Quote
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 - 10/30/2013 :  13:39:18  Show Profile  Reply with Quote
Yes,thanks
how I can do it with charindex?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/30/2013 :  13:43:25  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 10/30/2013 :  13:46:09  Show Profile  Reply with Quote
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 - 10/30/2013 :  13:49:28  Show Profile  Reply with Quote
Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000