|
-
Dec 10th, 2006, 02:17 PM
#1
Thread Starter
Hyperactive Member
what's wrong with this wildcard character?
I'm using the wonderful AS400 DB2 for an SQL assignment (not by my choice!) and nobody in the class, the teacher included, can get the wildcard characters to work. If I remember correctly, it's a % for a * and an underscore for a single replacement character. I think I also have to use like instead of = when using a wildcard character but any way I write the statement, it won't run. For example, I know that "select * from team where teamnm like '%s%' will not return any results but it should cuz there's lots with an s in the name. I can't figure out what I'm missing but for an assignment we need to use them. I already used substr on one but another question is return all the records that end with a certain string so if anyone knows a test just the end trick or how to get wildcards to work, that'd be awesome.
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Dec 10th, 2006, 03:31 PM
#2
Hyperactive Member
Re: what's wrong with this wildcard character?
And what is the the whole sentence?
-
Dec 10th, 2006, 05:43 PM
#3
Thread Starter
Hyperactive Member
Re: what's wrong with this wildcard character?
it's:
select team.teamnm, teamldr from member, team where team.teamnm = member.teamnm and mbrtitle like '%Spec'
Now I did get it to work properly when I replaced '%Spec' with '%Spec%' but that's not correct because it has to be the last 4 letters in the value. I have absolutely no idea why no records are returned with the single % one because there are 2 that end with Spec and I bet I'll lose points if they say it could technically pick up 'Specifications Manager'
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Dec 10th, 2006, 05:59 PM
#4
Re: what's wrong with this wildcard character?
Check the data.. the chances are that there is white space (or something else 'hidden') at the end of it.
-
Dec 10th, 2006, 07:11 PM
#5
Thread Starter
Hyperactive Member
Re: what's wrong with this wildcard character?
lol dude, this is the AS400. You can't even use the mouse let alone just bring up a data table object to analyze :P select * IS the look at the table command. There's only a character datatype as far as I know and it always tacks on extra spaces but I don't remember it ever picking them up quite like that before.
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Dec 10th, 2006, 07:22 PM
#6
Re: what's wrong with this wildcard character?
It doesn't matter what tools are available, you can still check what the field contains. eg:
Code:
select mbrtitle + '**' from tablename where mbrtitle like '%Spec%'
-
Dec 10th, 2006, 07:53 PM
#7
Re: what's wrong with this wildcard character?
Sounds like CHAR - with trailing white spaces - could be your issue...
Si gave a very nice technique for seeing "what's in a column" - by wrapping some delimiters around it in the SELECT.
AS400? Where in the world is this school anyway?
-
Dec 10th, 2006, 10:50 PM
#8
Thread Starter
Hyperactive Member
-
Dec 11th, 2006, 02:29 AM
#9
Hyperactive Member
Re: what's wrong with this wildcard character?
And this AS400 can have a syntax like:
"select team.teamnm, teamldr from member, team where ..."?
-
Dec 11th, 2006, 12:04 PM
#10
Thread Starter
Hyperactive Member
Re: what's wrong with this wildcard character?
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Dec 11th, 2006, 01:10 PM
#11
Re: what's wrong with this wildcard character?
That join syntax (with join conditions in the Where clause) used to be the standard, and is still supported by many/all DBMS's. Unfortunately the 'new' way isn't standardised across DBMS's - even MS Access and MS SQL Server use slightly different formatting!
It's annoying that the concatenation doesn't work.. the only alternative I can think of at the moment would be to do something like this (probably with an alternative for Len!):
Code:
select mbrtitle, Len(mbrtitle) from tablename where mbrtitle like '%Spec%'
..then you can count the characters displayed, and compare it. Not sure how much that helps tho.
Assuming you have a function like RTrim (or Trim) available, this may well work:
Code:
select mbrtitle from tablename where RTrim(mbrtitle) like '%Spec'
-
Dec 11th, 2006, 06:19 PM
#12
Thread Starter
Hyperactive Member
Re: what's wrong with this wildcard character?
ya know, I bet there wasn't an rtrim but I did finish up the test today with that double %% statement and they damn well better mark it correct or they'll hear from my attorney!
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|