Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lengthy SQL giving me problems - can it be shortened?

Status
Not open for further replies.

kisell

Technical User
Jan 10, 2004
5
0
0
CA
I'm using a flash form and the checkbox values for Flash checkboxes are defaulted to false are have only a true or false set, this cannot be changed as that is the way Flash is, so no changing the name value.

All of the check boxes run independently.... (except for DINE_IN & DINE_OUT , i'll get to those later) How this works is the user selects what meal type they want and they can select more than one, then the user selects a dine_in or/and dine out value.

In the db there are records where both dine_in and dine_out apply to the meal, so i included that db value into the selection(s). So basically what i'm doing is creating the sql where the first set of selection are true and where dine_in or/and dine_out are selected and pulling all info for those records, then i'm displaying them in a interactive pie chart in flash. The flash aspect i have no problem with its the asp.

I've managed to create this page but Flash only properly gets the values when the sql is "select * from logbook" another words when no selection is made, i'm thinking this is becasue the sql is too much of a hack job, needs to be more refined. This is my asp page (maybe there is some ?other? reason flash can only grab the value pairs when the sql = "select * from logbook" and i've response.writen the sql in this long version and it is like this format:
sql = "select * from logbook WHERE cusine IN ('AFRICAN','GERMAN') AND eat IN ('BOTH','DINE_OUT')"



code:--------------------------------------------------------------------------------

DINE_IN = Request.Form("DINE_IN")
DINE_OUT = Request.Form("DINE_OUT")

Dim Serv, Conn, RecordView, Ename, output, collect, SQL, Eeat, Ephone, collectaa
Dim collectbb, collectdd , collect4, collectfg, collecthi, collect6, collect7, collectuu
Dim eoutput, eeoutput, e4output, e6eoutput, ae2output, eb7output, e7output, e9output, emoutput

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DBQ=" & Server.MapPath("\4d9b\db.mdb") & ";" & _
"DRIVER=Microsoft Access Driver (*.mdb)"

SQL = "SELECT * FROM logbook WHERE cusine IN ("
AFRICAN = Request.Form("AFRICAN")
If AFRICAN = "true" Then
SQL = SQL & "'AFRICAN',"
End If
CARIBBEAN = Request.Form("CARIBBEAN")
If CARIBBEAN = "true" Then
SQL = SQL & "'CARIBBEAN',"
End If
CHINESE = Request.Form("CHINESE")
If CHINESE = "true" Then
SQL = SQL & "'CHINESE',"
End If
CONTINENTAL = Request.Form("CONTINENTAL")
If CONTINENTAL = "true" Then
SQL = SQL & "'CONTINENTAL',"
End If
DUTCH = Request.Form("DUTCH")
If DUTCH = "true" Then
SQL = SQL & "DUTCH',"
End If
EAST_INDIAN = Request.Form("EAST_INDIAN")
If EAST_INDIAN = "true" Then
SQL = SQL & "'EAST_INDIAN',"
End If
ENGLISH = Request.Form("ENGLISH")
If ENGLISH = "true" Then
SQL = SQL & "'ENGLISH',"
End If
ETHIOPIAN = Request.Form("ETHIOPIAN")
If ETHIOPIAN = "true" Then
SQL = SQL & "'ETHIOPIAN',"
End If
FONDUES = Request.Form("FONDUES")
If FONDUES = "true" Then
SQL = SQL & "'FONDUE',"
End If
FRENCH = Request.Form("FRENCH")
If FRENCH = "true" Then
SQL = SQL & "'FRENCH',"
End If
FUSION = Request.Form("FUSION")
If FUSION = "true" Then
SQL = SQL & "'FUSION',"
End If
GERMAN = Request.Form("GERMAN")
If GERMAN = "true" Then
SQL = SQL & "'GERMAN',"
End If
GREEK = Request.Form("GREEK")
If GREEK = "true" Then
SQL = SQL & "'GREEK',"
End If
ITALIAN = Request.Form("ITALIAN")
If ITALIAN = "true" Then
SQL = SQL & "'ITALIAN',"
End If
JAPANESE = Request.Form("JAPANESE")
If JAPANESE = "true" Then
SQL = SQL & "'JAPANESE',"
End If
JEWISH = Request.Form("JEWISH")
If JEWISH = "true" Then
SQL = SQL & "'JEWISH',"
End If
KOREAN = Request.Form("KOREAN")
If KOREAN = "true" Then
SQL = SQL & "'KOREAN',"
End If
MEDITERRANEAN = Request.Form("MEDITERRANEAN")
If MEDITERRANEAN = "true" Then
SQL = SQL & "'MEDITERRANEAN',"
End If
MEXICAN = Request.Form("MEXICAN")
If MEXICAN = "true" Then
SQL = SQL & "'MEXICAN',"
End If
MONGOLIAN = Request.Form("MONGOLIAN")
If MONGOLIAN = "true" Then
SQL = SQL & "'MONGOLIAN',"
End If
PAKISTANI = Request.Form("PAKISTANI")
If PAKISTANI = "true" Then
SQL = SQL & "'PAKISTANI',"
End If
PHILIPPINE = Request.Form("PHILIPPINE")
If PHILIPPINE = "true" Then
SQL = SQL & "'PHILIPPINE',"
End If
PIZZA = Request.Form("PIZZA")
If PIZZA = "true" Then
SQL = SQL & "'PIZZA',"
End If
PORTUGUESE = Request.Form("PORTUGUESE")
If PORTUGUESE = "true" Then
SQL = SQL & "'PORTUGUESE',"
End If
RIBS = Request.Form("RIBS")
If RIBS = "true" Then
SQL = SQL & "'RIBS',"
End If
STEAK_HOUSES = Request.Form("STEAK_HOUSES")
If STEAK_HOUSES = "true" Then
SQL = SQL & "'STEAK_HOUSES',"
End If
THAILAND = Request.Form("THAILAND")
If THAILAND = "true" Then
SQL = SQL & "'THAILAND',"
End If
UKRAINIAN = Request.Form("UKRAINIAN")
If UKRAINIAN = "true" Then
SQL = SQL & "'UKRAINIAN',"
End If
VEGETARIAN = Request.Form("VEGETARIAN")
If VEGETARIAN = "true" Then
SQL = SQL & "'VEGETARIAN',"
End If
VIETNAMESE = Request.Form("VIETNAMESE")
If VIETNAMESE = "true" Then
SQL = SQL & "'VIETNAMESE',"
End If
WEST_INDIAN = Request.Form("WEST_INDIAN")
If WEST_INDIAN = "true" Then
SQL = SQL & "'WEST_INDIAN'"
End If
If (DINE_IN = "true" AND DINE_OUT = "true") Then
SQL = SQL & ") AND eat IN ('BOTH','DINE_IN','DINE_OUT')"
elseIf (DINE_IN = "true" AND DINE_OUT = "false") Then
SQL = SQL & ") AND eat IN ('BOTH','DINE_IN')"
elseIf (DINE_IN = "false" AND DINE_OUT = "true") Then
SQL = SQL & ") AND eat IN ('BOTH','DINE_OUT')"
End If

set RecordView = Conn.Execute(SQL)

Do While Not RecordView.EOF
Ername=RecordView("rname")
Eeat=RecordView("eat")
Ephone=RecordView("phone")
Eaddress=RecordView("address")
Ecusine=RecordView("cusine")
Ehours=RecordView("hours")
Especial=RecordView("special")
Eaddition1=RecordView("addition1")
Eaddition2=RecordView("addition2")
Ecrew=RecordView("crew")

collect =collect & Ername&","
collectaa =collectaa & Eeat&","
collectbb =collectbb & Ephone&","
collectdd =collectdd & Eaddress&","
collect4 =collect4 & Ecusine&","
collectfg =collectfg & Ehours&","
collecthi =collecthi & Especial&","
collect6 =collect6 & Eaddition1&","
collect7 =collect7 & Eaddition2&","
collectuu =collectuu & Ecrew&","

RecordView.MoveNext
Loop

output="&output="& collect
Response.Write output
Response.Write "end&"

eoutput="eoutput="& collectaa
Response.Write eoutput
Response.Write "end&"

eeoutput="eeoutput="& collectbb
Response.Write eeroutput
Response.Write "end&"

e4output="e4output="& collectdd
Response.Write eeoutput
Response.Write "end&"

e6eoutput="e6eoutput="& collect4
Response.Write eeoutput
Response.Write "end&"

ea2output="ea2output="& collectfg
Response.Write eeoutput
Response.Write "end&"

eb7output="eb7output="& collecthi
Response.Write eeoutput
Response.Write "end&"

e7output="e7output="& collect6
Response.Write eeoutput
Response.Write "end&"

e9output="e9output="& collect7
Response.Write eeoutput
Response.Write "end&"

emoutput="emoutput="& collectuu
Response.Write eeoutput
Response.Write "end&"

Counter = 1

Response.Write "Counter=" & Counter
Response.Write "&"

RecordView.Close
Set RecordView = Nothing
Set Conn = Nothing
 
Kisell, do you know a certain 2cxc??

thread333-742928

hth,
Foxbox
 
Ya thats me i lost 2cxc login password and didn't give login info correct email address, so i had to create another handle
 
too bad this forum didn't have a handles merge button
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top