January 25, 2012 at 5:02 pm
Could some one help with my search string. I have apth like 1-1-1 and there could be 10-20-1 and i only want to select the first character based on the parameter length e.g if i pass in 10 it will only select the Path_String 10 that begin with 10 or it was 1 it would select the Path_string Starting at 1
SELECT ID, AddedBy, Title, Path_String FROM MyTable WHERE Path_String Like '%' + @Paramter + '%'; this isn't what I want.
January 25, 2012 at 5:06 pm
SELECT ID, AddedBy, Title, Path_String
FROM MyTable
WHERE
Path_String Like @Paramter + '%'
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgJanuary 25, 2012 at 5:11 pm
That still selects 1, 12, 13 etc if the parameter is just 1
January 25, 2012 at 5:14 pm
kirkdm01 (1/25/2012)
Will that select 1 and 12 where the parameter could just be 1 because i just would like it to select 1
OOPS!
SELECT ID, AddedBy, Title, Path_String
FROM MyTable
WHERE
Path_String Like @Paramter + '-%'
Oh, and read the article referenced in my signature, Sample data, DDL and desired output will help. 🙂
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgJanuary 25, 2012 at 5:16 pm
I tried you're second approach and i get no results if i put in 13, 12 or 1
January 25, 2012 at 5:24 pm
kirkdm01 (1/25/2012)
I tried you're second approach and i get no results if i put in 13, 12 or 1
Read the article referenced in my signature please.
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgJanuary 25, 2012 at 9:38 pm
kirkdm01 (1/25/2012)
I tried you're second approach and i get no results if i put in 13, 12 or 1
If you spell "Parameter" correctly :-P, Jason's code seems to do the trick...
DECLARE @MyTable TABLE (Path_String VARCHAR(100));
INSERT INTO @MyTable (Path_String)
SELECT '1-9-8' UNION ALL
SELECT '12-1-2' UNION ALL
SELECT '13-3-4' UNION ALL
SELECT '15-5-6'
;
DECLARE @Parameter VARCHAR(100);
SELECT @Parameter = '1';
SELECT Path_String
FROM @MyTable
WHERE
Path_String Like @Parameter + '-%'
;
--Jeff Moden
Change is inevitable... Change for the better is not.
January 26, 2012 at 3:25 am
It ended being the hyphen character being the problem so i use '/%' instead and it worked
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply