SQL comparing string smaller than field type is set to?

liunx

Guest
I have a field type of char(10), There can only be two values in it, "Yes/No" or "True/False"

I want to compare a string to the value in that field, however, if i want to compare "Yes/No" to that field i have to use "Yes/No " to compare since that's 10 chars. Is there like a Left() method or something to have it start comparing at the left and stop comparing once it gets to the 'o' in No?

Thanks in advance!

-Jasonit's hard to tell.. but i have to used "Yes/No " <-- has 2 spaces after "No"a couple of ways to do it but I am a little lost on what you are trying to do. why have both in there?I'm creating a web application to make online tests and surveys for the research place i work for. I have one data base that has a unique key for every question, in that table is also what test that question is for.. then i have a table for each of the types of questions that holds the extra information... such as for a boolean question, it can have values of yes/no or true/false.. etc
for multiple choice it has fields of number of options, and what those options are... a text line question has a field of how many chars do you want the form size to be,

blah blah blah =PNow I have another reason to know this... I also have a table with the names of all the tests in it. well, when i create a Test, it makes 2 new tables...

One table is named (The New Tests Name)_Answers
and (The New Tests Name)_Grades

What's happening is when I try to pull up that new Tests name, it's pulling it with all the spaces at the end... so when i try to open the table.. say for instance i have a test called "MyTest"... I want to open "MyTest_Grade"
Well I set a variable in asp to the name column of the entry i want, I'm not getting "MyTest" it's giving me "MyTest " Thus screwing up the table name when i make my SQL query.I would use 1 or 0 as in almost every language

1 = true/yes
0 = false/no

that way you only have to compare the number instead of yes or true. but if you want you can try

SELECT IF(STRCMP('test','test1'),'no','yes');
-> 'no'

or something to the effect

not sure how you want to compareDefinitely go with Scoutt's idea here.

People think they need to put very detailed values in their table fields, but as long as you know what the values represent, that's all that matters. It's not like code that you have to worry about commenting and describing very well, if someone really needs to know what your values are or mean other than you, they should rely on your could to find that out.

Also, storing and searching values like "Yes/No" require much more processing and overhead than a values like "T" and "Y" or even be 1 and 0.Great comments from both Scoutt and Putts. You both are exactly on track, you should use bit, then int if possible to describe data. You can use another table for the definitions if necessary, but you store the vast majority of the data in bit or int types. These take up the least spaces, are easily indexed and searched.

To make a dynamic test application would take a lot of database planning. what database are you using? I have a sample of such a database in sqlserver if you would like to see the schema (database diagram).I went with the bit idea on the yes/no or true/false option, however it's a little more tricky than that for another field. The administrators of this application will be able to add tests, and thus have to name that test. These test names all go into a table that stores all the tests names, then in the questions table, questions that belong to this test have a field for what test they belong to.. and this is where this test name is put in.. and this again is another field i have to search. I made that field length, and the field length of the field in the tests table the same. There for when i set a variable from one of the fields, it does look the same as the other field when comparing. However if I ever have to "hard code" a field name in, it won't look the same. I realize I could maybe put another field in the tests table that is an autonumber or something. hmmm.... I might have to do so if the problem arises. Thanks for the input, it's helped to sculpt my design. I am a n00b at this stuff, the boss was like, do it, teach yourself.. I'm a college student and have had no experience in databasing, it hasn't been too hard to pick up though =P
I'm using SQL Server 2000, and IIS
-jasonyou would use a table to store test names like so:

id....testName
1.....test number one


then in your questions table, it would reference the id:

id.....testID.....question
1......1..........what is Scoutts real name?


you would NEVER hardcode the test name outside of the testNames table... you would only use the ID of the test.

I'll try to put together the database schema tonight for you. Its in sqlserver2000, so if you like it I'll give you the scripts to create the db on your server.
 
Top