|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
select based on containing only certain charactersI need to select rows in a table where a particular column contains
only the following characters and not in any particular order. "AZ{<" So "A", "Z", "{", and "<" without the quotes. If that's all there is in the data for a column, select it. Example: Positive hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAA Negative hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAAG ^^^ second one has a G at the end. Thanks. JR Your performance may not be great, but you could do it like this:
DECLARE @t TABLE (c1 varchar(50)) INSERT INTO @t VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAA') INSERT INTO @t VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAAG') SELECT c1 FROM @t WHERE c1 NOT LIKE '%[^AZ<{]%' HTH, Stu JR wrote: Show quote > I need to select rows in a table where a particular column contains > only the following characters and not in any particular order. "AZ{<" > So "A", "Z", "{", and "<" without the quotes. If that's all there is > in the data for a column, select it. > > Example: > > Positive hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAA > Negative hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAAG > ^^^ second one has a G at the end. > > Thanks. > > JR How about if I had a | (pipe) or > (greater than sign. These do not
seem to be returning anything. So if I do something like DECLARE @t TABLE (c1 varchar(50)) INSERT INTO @t VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAA') INSERT INTO @t VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAAG') INSERT INTO @t VALUES ('AZ') SELECT c1 FROM @t WHERE c1 NOT LIKE '%[^AZ>|]%' All I get is the last AZ value. Not the first two. Stu wrote: Show quote > Your performance may not be great, but you could do it like this: > > DECLARE @t TABLE (c1 varchar(50)) > > INSERT INTO @t > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAA') > > INSERT INTO @t > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAAG') > > SELECT c1 > FROM @t > WHERE c1 NOT LIKE '%[^AZ<{]%' > > HTH, > Stu > > > JR wrote: > > I need to select rows in a table where a particular column contains > > only the following characters and not in any particular order. "AZ{<" > > So "A", "Z", "{", and "<" without the quotes. If that's all there is > > in the data for a column, select it. > > > > Example: > > > > Positive hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAA > > Negative hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAAG > > ^^^ second one has a G at the end. > > > > Thanks. > > > > JR I mean not the first one.
JR wrote: Show quote > How about if I had a | (pipe) or > (greater than sign. These do not > seem to be returning anything. So if I do something like > > DECLARE @t TABLE (c1 varchar(50)) > > INSERT INTO @t > VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAA') > > INSERT INTO @t > VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAAG') > > INSERT INTO @t > VALUES ('AZ') > > SELECT c1 > FROM @t > WHERE c1 NOT LIKE '%[^AZ>|]%' > > All I get is the last AZ value. Not the first two. > > Stu wrote: > > Your performance may not be great, but you could do it like this: > > > > DECLARE @t TABLE (c1 varchar(50)) > > > > INSERT INTO @t > > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAA') > > > > INSERT INTO @t > > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAAG') > > > > SELECT c1 > > FROM @t > > WHERE c1 NOT LIKE '%[^AZ<{]%' > > > > HTH, > > Stu > > > > > > JR wrote: > > > I need to select rows in a table where a particular column contains > > > only the following characters and not in any particular order. "AZ{<" > > > So "A", "Z", "{", and "<" without the quotes. If that's all there is > > > in the data for a column, select it. > > > > > > Example: > > > > > > Positive hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAA > > > Negative hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAAG > > > ^^^ second one has a G at the end. > > > > > > Thanks. > > > > > > JR Hmm. I'm running it on a SQL 2005 setup, and it worked fine for me; I
got two rows returned; the exception was the one with the G. As far as I know, neither the < or the | simple should have any meaning in a wildcard scenario. Can you verify your results again? Stu JR wrote: Show quote > I mean not the first one. > JR wrote: > > How about if I had a | (pipe) or > (greater than sign. These do not > > seem to be returning anything. So if I do something like > > > > DECLARE @t TABLE (c1 varchar(50)) > > > > INSERT INTO @t > > VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAA') > > > > INSERT INTO @t > > VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAAG') > > > > INSERT INTO @t > > VALUES ('AZ') > > > > SELECT c1 > > FROM @t > > WHERE c1 NOT LIKE '%[^AZ>|]%' > > > > All I get is the last AZ value. Not the first two. > > > > Stu wrote: > > > Your performance may not be great, but you could do it like this: > > > > > > DECLARE @t TABLE (c1 varchar(50)) > > > > > > INSERT INTO @t > > > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAA') > > > > > > INSERT INTO @t > > > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAAG') > > > > > > SELECT c1 > > > FROM @t > > > WHERE c1 NOT LIKE '%[^AZ<{]%' > > > > > > HTH, > > > Stu > > > > > > > > > JR wrote: > > > > I need to select rows in a table where a particular column contains > > > > only the following characters and not in any particular order. "AZ{<" > > > > So "A", "Z", "{", and "<" without the quotes. If that's all there is > > > > in the data for a column, select it. > > > > > > > > Example: > > > > > > > > Positive hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAA > > > > Negative hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAAG > > > > ^^^ second one has a G at the end. > > > > > > > > Thanks. > > > > > > > > JR OK, tested again and I'm getting the first and last value. However I
shouldn't get the second value as it doesn't contain the pipe or greater than characters, just "AZ". I'm not sure, however when I test this with fields of type text only the last one is returned. Stu wrote: Show quote > Hmm. I'm running it on a SQL 2005 setup, and it worked fine for me; I > got two rows returned; the exception was the one with the G. > > As far as I know, neither the < or the | simple should have any meaning > in a wildcard scenario. > > Can you verify your results again? > > Stu > > JR wrote: > > I mean not the first one. > > JR wrote: > > > How about if I had a | (pipe) or > (greater than sign. These do not > > > seem to be returning anything. So if I do something like > > > > > > DECLARE @t TABLE (c1 varchar(50)) > > > > > > INSERT INTO @t > > > VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAA') > > > > > > INSERT INTO @t > > > VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAAG') > > > > > > INSERT INTO @t > > > VALUES ('AZ') > > > > > > SELECT c1 > > > FROM @t > > > WHERE c1 NOT LIKE '%[^AZ>|]%' > > > > > > All I get is the last AZ value. Not the first two. > > > > > > Stu wrote: > > > > Your performance may not be great, but you could do it like this: > > > > > > > > DECLARE @t TABLE (c1 varchar(50)) > > > > > > > > INSERT INTO @t > > > > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAA') > > > > > > > > INSERT INTO @t > > > > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAAG') > > > > > > > > SELECT c1 > > > > FROM @t > > > > WHERE c1 NOT LIKE '%[^AZ<{]%' > > > > > > > > HTH, > > > > Stu > > > > > > > > > > > > JR wrote: > > > > > I need to select rows in a table where a particular column contains > > > > > only the following characters and not in any particular order. "AZ{<" > > > > > So "A", "Z", "{", and "<" without the quotes. If that's all there is > > > > > in the data for a column, select it. > > > > > > > > > > Example: > > > > > > > > > > Positive hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAA > > > > > Negative hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAAG > > > > > ^^^ second one has a G at the end. > > > > > > > > > > Thanks. > > > > > > > > > > JR Hey JR,
Can you post either actual data definition language scripts OR a sample that illustrates the problem (ie, a column of type text with sample data)? I think I understand what you are describing, but it would be nice to make sure we're on the same page. Stu JR wrote: Show quote > OK, tested again and I'm getting the first and last value. However I > shouldn't get the second value as it doesn't contain the pipe or > greater than characters, just "AZ". I'm not sure, however when I test > this with fields of type text only the last one is returned. > > > Stu wrote: > > Hmm. I'm running it on a SQL 2005 setup, and it worked fine for me; I > > got two rows returned; the exception was the one with the G. > > > > As far as I know, neither the < or the | simple should have any meaning > > in a wildcard scenario. > > > > Can you verify your results again? > > > > Stu > > > > JR wrote: > > > I mean not the first one. > > > JR wrote: > > > > How about if I had a | (pipe) or > (greater than sign. These do not > > > > seem to be returning anything. So if I do something like > > > > > > > > DECLARE @t TABLE (c1 varchar(50)) > > > > > > > > INSERT INTO @t > > > > VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAA') > > > > > > > > INSERT INTO @t > > > > VALUES ('AZ|>ZAZZZZZZZAAAAAAAAAAG') > > > > > > > > INSERT INTO @t > > > > VALUES ('AZ') > > > > > > > > SELECT c1 > > > > FROM @t > > > > WHERE c1 NOT LIKE '%[^AZ>|]%' > > > > > > > > All I get is the last AZ value. Not the first two. > > > > > > > > Stu wrote: > > > > > Your performance may not be great, but you could do it like this: > > > > > > > > > > DECLARE @t TABLE (c1 varchar(50)) > > > > > > > > > > INSERT INTO @t > > > > > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAA') > > > > > > > > > > INSERT INTO @t > > > > > VALUES ('AZ{<ZAZZZZZZZAAAAAAAAAAG') > > > > > > > > > > SELECT c1 > > > > > FROM @t > > > > > WHERE c1 NOT LIKE '%[^AZ<{]%' > > > > > > > > > > HTH, > > > > > Stu > > > > > > > > > > > > > > > JR wrote: > > > > > > I need to select rows in a table where a particular column contains > > > > > > only the following characters and not in any particular order. "AZ{<" > > > > > > So "A", "Z", "{", and "<" without the quotes. If that's all there is > > > > > > in the data for a column, select it. > > > > > > > > > > > > Example: > > > > > > > > > > > > Positive hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAA > > > > > > Negative hit if data in column was: AZ{<ZAZZZZZZZAAAAAAAAAAG > > > > > > ^^^ second one has a G at the end. > > > > > > > > > > > > Thanks. > > > > > > > > > > > > JR >> I need to select rows in a table where a particular column contains only thfollowing characters and not in any particular order. "AZ{<" << SELECT wordFROM Foobar WHERE REPLACE (REPLACE (REPLACE (REPLACE (word, 'A', ''), 'Z', ''), '{', ''), '<', '') = ''; Note that spaces count as characters. --CELKO-- wrote:
> >> I need to select rows in a table where a particular column contains only thfollowing characters and not in any particular order. "AZ{<" << Thanks for the reply. I should have mentioned that the field in> > SELECT word > FROM Foobar > WHERE REPLACE > (REPLACE > (REPLACE > (REPLACE (word, 'A', ''), > 'Z', ''), > '{', ''), > '<', '') = ''; > > Note that spaces count as characters. question here is of type "text" so SQL Server seems unhappy with this. Probably the equals clause or something. |
|||||||||||||||||||||||