Wildcard expression in SQL Server The Next CEO of Stack OverflowHow do I perform an IF…THEN in an SQL SELECT?How to return only the Date from a SQL Server DateTime datatypeHow to check if a column exists in a SQL Server table?Check if table exists in SQL ServerHow to validate an email address using a regular expression?Regular expression to match a line that doesn't contain a word?LEFT JOIN vs. LEFT OUTER JOIN in SQL ServerInserting multiple rows in a single SQL query?How do I UPDATE from a SELECT in SQL Server?Find all tables containing column with specified name - MS SQL Server
Why isn't the Mueller report being released completely and unredacted?
Unclear about dynamic binding
Grabbing quick drinks
What flight has the highest ratio of time difference to flight time?
Can we say or write : "No, it'sn't"?
A small doubt about the dominated convergence theorem
Do I need to write [sic] when a number is less than 10 but isn't written out?
Running a General Election and the European Elections together
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
Does soap repel water?
Reference request: Grassmannian and Plucker coordinates in type B, C, D
INSERT to a table from a database to other (same SQL Server) using Dynamic SQL
Is French Guiana a (hard) EU border?
Are police here, aren't itthey?
Why is my new battery behaving weirdly?
Why the difference in type-inference over the as-pattern in two similar function definitions?
How did people program for Consoles with multiple CPUs?
How to check if all elements of 1 list are in the *same quantity* and in any order, in the list2?
Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?
Why is quantifier elimination desirable for a given theory?
What was the first Unix version to run on a microcomputer?
Why do airplanes bank sharply to the right after air-to-air refueling?
What happened in Rome, when the western empire "fell"?
Is there a difference between "Fahrstuhl" and "Aufzug"
Wildcard expression in SQL Server
The Next CEO of Stack OverflowHow do I perform an IF…THEN in an SQL SELECT?How to return only the Date from a SQL Server DateTime datatypeHow to check if a column exists in a SQL Server table?Check if table exists in SQL ServerHow to validate an email address using a regular expression?Regular expression to match a line that doesn't contain a word?LEFT JOIN vs. LEFT OUTER JOIN in SQL ServerInserting multiple rows in a single SQL query?How do I UPDATE from a SELECT in SQL Server?Find all tables containing column with specified name - MS SQL Server
I know that, the following query returns the rows, which are contain the exact 5 characters between the A
and G
select *
from
(select 'prefixABBBBBGsuffix' code /*this will be returned. */
union
select 'prefixABBBBGsuffix') rex
where
code like '%A_____G%'
But I want 17 character between A
and G
, then like
condition must have 17 underscores. So I search little in google I found []
will be used in like. Then I tried so for.
select *
from
(select 'AprefixABBBBBGsuffixG' code
union
select 'AprefixABBBBGsuffixG') rex
where
code like '%A[_]^17G%' /*As per my understanding, '[]' makes a set. And
'^17' would be power of the set (like Mathematics).*/
Then it returns the NULL set. How can I search rows which has certain number of character in the set []
?
Note:
I'm using SQL Server 2012.
regex tsql sql-server-2012 wildcard
add a comment |
I know that, the following query returns the rows, which are contain the exact 5 characters between the A
and G
select *
from
(select 'prefixABBBBBGsuffix' code /*this will be returned. */
union
select 'prefixABBBBGsuffix') rex
where
code like '%A_____G%'
But I want 17 character between A
and G
, then like
condition must have 17 underscores. So I search little in google I found []
will be used in like. Then I tried so for.
select *
from
(select 'AprefixABBBBBGsuffixG' code
union
select 'AprefixABBBBGsuffixG') rex
where
code like '%A[_]^17G%' /*As per my understanding, '[]' makes a set. And
'^17' would be power of the set (like Mathematics).*/
Then it returns the NULL set. How can I search rows which has certain number of character in the set []
?
Note:
I'm using SQL Server 2012.
regex tsql sql-server-2012 wildcard
sql server doesn't support full regex.
– scsimon
Mar 8 at 20:32
in sql, [] can make a set, like [A-Za-z] which matches exactly one alphabet char upper and lower case, but when used with _ it's an escape. example, like '%5[%]' will match any string ending in 5% and [_] means a literal _ and []] means a literal ].
– JBJ
Mar 8 at 23:17
add a comment |
I know that, the following query returns the rows, which are contain the exact 5 characters between the A
and G
select *
from
(select 'prefixABBBBBGsuffix' code /*this will be returned. */
union
select 'prefixABBBBGsuffix') rex
where
code like '%A_____G%'
But I want 17 character between A
and G
, then like
condition must have 17 underscores. So I search little in google I found []
will be used in like. Then I tried so for.
select *
from
(select 'AprefixABBBBBGsuffixG' code
union
select 'AprefixABBBBGsuffixG') rex
where
code like '%A[_]^17G%' /*As per my understanding, '[]' makes a set. And
'^17' would be power of the set (like Mathematics).*/
Then it returns the NULL set. How can I search rows which has certain number of character in the set []
?
Note:
I'm using SQL Server 2012.
regex tsql sql-server-2012 wildcard
I know that, the following query returns the rows, which are contain the exact 5 characters between the A
and G
select *
from
(select 'prefixABBBBBGsuffix' code /*this will be returned. */
union
select 'prefixABBBBGsuffix') rex
where
code like '%A_____G%'
But I want 17 character between A
and G
, then like
condition must have 17 underscores. So I search little in google I found []
will be used in like. Then I tried so for.
select *
from
(select 'AprefixABBBBBGsuffixG' code
union
select 'AprefixABBBBGsuffixG') rex
where
code like '%A[_]^17G%' /*As per my understanding, '[]' makes a set. And
'^17' would be power of the set (like Mathematics).*/
Then it returns the NULL set. How can I search rows which has certain number of character in the set []
?
Note:
I'm using SQL Server 2012.
regex tsql sql-server-2012 wildcard
regex tsql sql-server-2012 wildcard
edited Mar 8 at 16:44
marc_s
583k13011241270
583k13011241270
asked Mar 8 at 15:47
PugalPugal
40214
40214
sql server doesn't support full regex.
– scsimon
Mar 8 at 20:32
in sql, [] can make a set, like [A-Za-z] which matches exactly one alphabet char upper and lower case, but when used with _ it's an escape. example, like '%5[%]' will match any string ending in 5% and [_] means a literal _ and []] means a literal ].
– JBJ
Mar 8 at 23:17
add a comment |
sql server doesn't support full regex.
– scsimon
Mar 8 at 20:32
in sql, [] can make a set, like [A-Za-z] which matches exactly one alphabet char upper and lower case, but when used with _ it's an escape. example, like '%5[%]' will match any string ending in 5% and [_] means a literal _ and []] means a literal ].
– JBJ
Mar 8 at 23:17
sql server doesn't support full regex.
– scsimon
Mar 8 at 20:32
sql server doesn't support full regex.
– scsimon
Mar 8 at 20:32
in sql, [] can make a set, like [A-Za-z] which matches exactly one alphabet char upper and lower case, but when used with _ it's an escape. example, like '%5[%]' will match any string ending in 5% and [_] means a literal _ and []] means a literal ].
– JBJ
Mar 8 at 23:17
in sql, [] can make a set, like [A-Za-z] which matches exactly one alphabet char upper and lower case, but when used with _ it's an escape. example, like '%5[%]' will match any string ending in 5% and [_] means a literal _ and []] means a literal ].
– JBJ
Mar 8 at 23:17
add a comment |
2 Answers
2
active
oldest
votes
same answer as previously but corrected. 17 wasn't the number, it was 18 and 19 for strings, also put in the len(textbetweenA and G) to show.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('_',19) + 'G%'
--and with [] the set would be [A-Za-z]. Notice this set does not match the A___________________G string.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('[A-Za-z]',19) + 'G%'
[A-Za-z0-9] matches one character within the scope of alphabet (both cases) or a number 0 through 9
I can't find any working information about another way to handle a number of chars like that, replicate is just a way to ease parameterization and typing.
It gives the exact answer, even I was added some data likeunion select 'A'+REPLICATE ('_',17)+'G'
– Pugal
Mar 9 at 7:21
But I cant understood, why19
was passed? I want 17 character. So my where clause asrex.code like '%A' + replicate('[A-Za-z]',17) + 'G%'
– Pugal
Mar 9 at 7:28
neither of the original examples with A and G on the ends had 17 chars between, one had 18 and one had 19. so I chose one of those numbers to show in the example. remove the extra character(s) and you can get 17 :)
– JBJ
Mar 9 at 8:10
add a comment |
I would use REPLICATE
to generate desired number of '_':
select * from (
select 'prefixABBBBBGsuffix' code
union
select 'prefixABBBBGsuffix'
) rex
where code like '%A' + REPLICATE('_',17) + 'G%';
Thanks for response.union select 'A'+REPLICATE ('_',17)+'G'
if I add this, it will be returned. So I go with @JBJ answer.
– Pugal
Mar 9 at 7:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066618%2fwildcard-expression-in-sql-server%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
same answer as previously but corrected. 17 wasn't the number, it was 18 and 19 for strings, also put in the len(textbetweenA and G) to show.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('_',19) + 'G%'
--and with [] the set would be [A-Za-z]. Notice this set does not match the A___________________G string.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('[A-Za-z]',19) + 'G%'
[A-Za-z0-9] matches one character within the scope of alphabet (both cases) or a number 0 through 9
I can't find any working information about another way to handle a number of chars like that, replicate is just a way to ease parameterization and typing.
It gives the exact answer, even I was added some data likeunion select 'A'+REPLICATE ('_',17)+'G'
– Pugal
Mar 9 at 7:21
But I cant understood, why19
was passed? I want 17 character. So my where clause asrex.code like '%A' + replicate('[A-Za-z]',17) + 'G%'
– Pugal
Mar 9 at 7:28
neither of the original examples with A and G on the ends had 17 chars between, one had 18 and one had 19. so I chose one of those numbers to show in the example. remove the extra character(s) and you can get 17 :)
– JBJ
Mar 9 at 8:10
add a comment |
same answer as previously but corrected. 17 wasn't the number, it was 18 and 19 for strings, also put in the len(textbetweenA and G) to show.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('_',19) + 'G%'
--and with [] the set would be [A-Za-z]. Notice this set does not match the A___________________G string.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('[A-Za-z]',19) + 'G%'
[A-Za-z0-9] matches one character within the scope of alphabet (both cases) or a number 0 through 9
I can't find any working information about another way to handle a number of chars like that, replicate is just a way to ease parameterization and typing.
It gives the exact answer, even I was added some data likeunion select 'A'+REPLICATE ('_',17)+'G'
– Pugal
Mar 9 at 7:21
But I cant understood, why19
was passed? I want 17 character. So my where clause asrex.code like '%A' + replicate('[A-Za-z]',17) + 'G%'
– Pugal
Mar 9 at 7:28
neither of the original examples with A and G on the ends had 17 chars between, one had 18 and one had 19. so I chose one of those numbers to show in the example. remove the extra character(s) and you can get 17 :)
– JBJ
Mar 9 at 8:10
add a comment |
same answer as previously but corrected. 17 wasn't the number, it was 18 and 19 for strings, also put in the len(textbetweenA and G) to show.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('_',19) + 'G%'
--and with [] the set would be [A-Za-z]. Notice this set does not match the A___________________G string.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('[A-Za-z]',19) + 'G%'
[A-Za-z0-9] matches one character within the scope of alphabet (both cases) or a number 0 through 9
I can't find any working information about another way to handle a number of chars like that, replicate is just a way to ease parameterization and typing.
same answer as previously but corrected. 17 wasn't the number, it was 18 and 19 for strings, also put in the len(textbetweenA and G) to show.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('_',19) + 'G%'
--and with [] the set would be [A-Za-z]. Notice this set does not match the A___________________G string.
select rex.*
from (
select len('prefixABBBBBGsuffix') leng, 'AprefixABBBBBGsuffixG' code
union
select len('prefixABBBBGsuffix'), 'AprefixABBBBGsuffixG'
union
select 0, 'A___________________G'
) rex
where
rex.code like '%A' + replicate('[A-Za-z]',19) + 'G%'
[A-Za-z0-9] matches one character within the scope of alphabet (both cases) or a number 0 through 9
I can't find any working information about another way to handle a number of chars like that, replicate is just a way to ease parameterization and typing.
edited Mar 9 at 4:27
answered Mar 8 at 23:10
JBJJBJ
18116
18116
It gives the exact answer, even I was added some data likeunion select 'A'+REPLICATE ('_',17)+'G'
– Pugal
Mar 9 at 7:21
But I cant understood, why19
was passed? I want 17 character. So my where clause asrex.code like '%A' + replicate('[A-Za-z]',17) + 'G%'
– Pugal
Mar 9 at 7:28
neither of the original examples with A and G on the ends had 17 chars between, one had 18 and one had 19. so I chose one of those numbers to show in the example. remove the extra character(s) and you can get 17 :)
– JBJ
Mar 9 at 8:10
add a comment |
It gives the exact answer, even I was added some data likeunion select 'A'+REPLICATE ('_',17)+'G'
– Pugal
Mar 9 at 7:21
But I cant understood, why19
was passed? I want 17 character. So my where clause asrex.code like '%A' + replicate('[A-Za-z]',17) + 'G%'
– Pugal
Mar 9 at 7:28
neither of the original examples with A and G on the ends had 17 chars between, one had 18 and one had 19. so I chose one of those numbers to show in the example. remove the extra character(s) and you can get 17 :)
– JBJ
Mar 9 at 8:10
It gives the exact answer, even I was added some data like
union select 'A'+REPLICATE ('_',17)+'G'
– Pugal
Mar 9 at 7:21
It gives the exact answer, even I was added some data like
union select 'A'+REPLICATE ('_',17)+'G'
– Pugal
Mar 9 at 7:21
But I cant understood, why
19
was passed? I want 17 character. So my where clause as rex.code like '%A' + replicate('[A-Za-z]',17) + 'G%'
– Pugal
Mar 9 at 7:28
But I cant understood, why
19
was passed? I want 17 character. So my where clause as rex.code like '%A' + replicate('[A-Za-z]',17) + 'G%'
– Pugal
Mar 9 at 7:28
neither of the original examples with A and G on the ends had 17 chars between, one had 18 and one had 19. so I chose one of those numbers to show in the example. remove the extra character(s) and you can get 17 :)
– JBJ
Mar 9 at 8:10
neither of the original examples with A and G on the ends had 17 chars between, one had 18 and one had 19. so I chose one of those numbers to show in the example. remove the extra character(s) and you can get 17 :)
– JBJ
Mar 9 at 8:10
add a comment |
I would use REPLICATE
to generate desired number of '_':
select * from (
select 'prefixABBBBBGsuffix' code
union
select 'prefixABBBBGsuffix'
) rex
where code like '%A' + REPLICATE('_',17) + 'G%';
Thanks for response.union select 'A'+REPLICATE ('_',17)+'G'
if I add this, it will be returned. So I go with @JBJ answer.
– Pugal
Mar 9 at 7:25
add a comment |
I would use REPLICATE
to generate desired number of '_':
select * from (
select 'prefixABBBBBGsuffix' code
union
select 'prefixABBBBGsuffix'
) rex
where code like '%A' + REPLICATE('_',17) + 'G%';
Thanks for response.union select 'A'+REPLICATE ('_',17)+'G'
if I add this, it will be returned. So I go with @JBJ answer.
– Pugal
Mar 9 at 7:25
add a comment |
I would use REPLICATE
to generate desired number of '_':
select * from (
select 'prefixABBBBBGsuffix' code
union
select 'prefixABBBBGsuffix'
) rex
where code like '%A' + REPLICATE('_',17) + 'G%';
I would use REPLICATE
to generate desired number of '_':
select * from (
select 'prefixABBBBBGsuffix' code
union
select 'prefixABBBBGsuffix'
) rex
where code like '%A' + REPLICATE('_',17) + 'G%';
answered Mar 8 at 15:49
Lukasz SzozdaLukasz Szozda
82k1070110
82k1070110
Thanks for response.union select 'A'+REPLICATE ('_',17)+'G'
if I add this, it will be returned. So I go with @JBJ answer.
– Pugal
Mar 9 at 7:25
add a comment |
Thanks for response.union select 'A'+REPLICATE ('_',17)+'G'
if I add this, it will be returned. So I go with @JBJ answer.
– Pugal
Mar 9 at 7:25
Thanks for response.
union select 'A'+REPLICATE ('_',17)+'G'
if I add this, it will be returned. So I go with @JBJ answer.– Pugal
Mar 9 at 7:25
Thanks for response.
union select 'A'+REPLICATE ('_',17)+'G'
if I add this, it will be returned. So I go with @JBJ answer.– Pugal
Mar 9 at 7:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066618%2fwildcard-expression-in-sql-server%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
sql server doesn't support full regex.
– scsimon
Mar 8 at 20:32
in sql, [] can make a set, like [A-Za-z] which matches exactly one alphabet char upper and lower case, but when used with _ it's an escape. example, like '%5[%]' will match any string ending in 5% and [_] means a literal _ and []] means a literal ].
– JBJ
Mar 8 at 23:17