PDA

Click to See Complete Forum and Search --> : Advanced SELECT. To hard for you!?


rancor
Sep 18th, 2000, 01:11 PM
Hi.

I got a database like this
Title | Language
Test1 en
Test2 en
Test3 se

and I want so search on the Title and with a language. Sometimes "en" and "se" and sometime just one language. I created this query but I can't make it work with the "language" selection. Any idéa how to combine several boolean expressions??


SQL = "SELECT * From Stories"
SQL = SQL & " WHERE Titel LIKE '%" & Request.Form("titel") & "%'"

If Request.Form("swedish") <> "ON" Then SQL = SQL & " AND Language = 'se'"
If Request.Form("english") <> "ON" Then SQL = SQL & " AND Language = 'en'"


Tnx!

parksie
Sep 18th, 2000, 01:14 PM
Try using:

AND (Language = 'se' OR Language = 'en')

RIVES
Sep 18th, 2000, 01:17 PM
Language can only have one value right? Then using "AND" would make it wrong... it should either be just

Swedish ... = 'se'
English ... = 'en'
Both ... 'se' OR 'en'

rancor
Sep 18th, 2000, 01:42 PM
Multiple language is OK.

I got error then I run this query:
SELECT * From Stories WHERE Titel LIKE '%all%' AND (Language = 'se' OR Language = 'en')

I think this looks okey but I got an unspecified error when I "rs.Open SQL, Conn"

I can run more simple questions like "SELECT * From Stories ORDER BY ID DESC"

RIVES
Sep 18th, 2000, 01:53 PM
Assuming that you just cut and paste this from your code,

is it because your column name WHERE Titel should be Title?

rancor
Sep 18th, 2000, 01:56 PM
I must use WHERE in the query and where shall I put "WHERE" if not at the current possition???

parksie
Sep 18th, 2000, 02:03 PM
He means replace Titel with Title.

rancor
Sep 18th, 2000, 02:10 PM
"titel" is right.

Titel is the swedish word for title and when I created the database I used all english words except the "titel". But that is not the problem because I can run questions like:

SELECT * From Stories WHERE Titel LIKE '%yellow%'

RIVES
Sep 18th, 2000, 02:20 PM
What exactly is your error message?

rancor
Sep 18th, 2000, 02:28 PM
search result: SELECT * From Stories WHERE Titel LIKE '%%%' AND (Language = 'en') fel '80004005'
Odefinierat fel

/stories.asp, line 389


I past the exact output from my ASP page. I print the variable SQL for debug and it's the "SELECT......" part.

The text "fel '80004005' Odefinierat fel" is "ERROR '80004005' underfined error" in english and that part is the server that says

/stories.asp, line 389 : That is the part where I execute the query:
rs.Open SQL, Conn

This is not fun anymore =(

rancor
Sep 18th, 2000, 02:54 PM
cool.. reserved words..

yeah. it works with [Language].. TNX!!!

eh.. works is a strong word. I don't get any errormessage now but I dont any hits.. strange.

Does SQL think that [Language] is a "string" now instead of a column?

RIVES
Sep 18th, 2000, 03:00 PM
exactly what is the datatype definition of your columns in your table? when you put things in a brace, it treats it as an onject. [TABLE], [COLUMN] etc. its not a string. Check your language column declaration... it should be char(2).

rancor
Sep 18th, 2000, 03:13 PM
duh..

I changed the name instead. Now is it called "Lang".

Thanks for your help!