Very Ugly SQL statement. Help Needed.

This is a discussion on "Very Ugly SQL statement. Help Needed." within the Classic ASP section. This forum, and the thread "Very Ugly SQL statement. Help Needed. are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 29th, 2006, 16:19
New Member
Join Date: Sep 2006
Location: Kansas
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Very Ugly SQL statement. Help Needed.

I'll try to make this as brief as possible. I am having trouble getting this SQL statement to work. Any suggestions would be appriciated. I am using Classic ASP with an Access Backend.

The object:
The user will submit a productid and stateid through a form to find a list of stores in the given state that sells the given product.

The DB schema:
wtbProducts (table)
productID
Alias

wtbProductWarehouses (table)
productID
warehouseID

wtbWarehouseStores (table)
warehouseID
storeID

wtbStoreStates (table)
storeID
stateID

wtbStores (table)
storeID
Alias (name of store)
WebAddress

Other tables which I don't think are needed in the SQL
wtbWarehouses (table)
warehouseID
Alias
CustomerNumber

wtbStates (table)
stateID
Code
Alias
Show

The data I want returned:
Alias and WebAddress from wtbStores

The code that I have written:
Code: Select all
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include  virtual="/Connections/Conn2.asp" -->
<%
    Dim conn, rs
    Set conn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.Recordset")
    conn.Open strConnect
    
    pid = Request.Form("productid")
    sid = Request.Form("stateid")
    
    SQL = " SELECT * FROM wtbStores " _
        & " WHERE storeID IN ( SELECT * " _
        & "                    FROM wtbStoreStates " _
        & "                    WHERE stateID = " & sid & ") " _
        & " AND storeID IN   ( SELECT * FROM wtbWarehouseStores " _
        & "                    WHERE warehouseID IN ( SELECT * " _
        & "                                              FROM wtbProductWarehouses " _
        & "                                              WHERE productID = " & pid & ")) "
        
    Set rs = conn.Execute(SQL)
%>

The Error that I am getting:
Microsoft JET Database Engine error '80040e14'

Syntax error. in query expression 'storeID IN ( SELECT * FROM wtbStoreStates WHERE stateID = ) AND storeID IN ( SELECT * FROM wtbWarehouseStores WHERE warehouseID IN ( SELECT * FROM wtbProductWarehouses WHERE productID = ))'.

/getStores.asp, line 21


Any suggestions?

Thanks,

Jason
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 29th, 2006, 16:37
New Member
Join Date: Sep 2006
Location: Kansas
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Very Ugly SQL statement. Help Needed.

Sorry. I forgot to explain the product/warehouse/store relationship...

Warehouses order different products. This relationship is set in wtbProductWarehouses. Stores then can order any of the products that a Warehouse carries. If a Warehouse does not carry a product the store can not order it. The relationship of stores to Warehouses is set in wtbWarehouseStores. Thus in my thinking we have to use the productid submitted from the form to find warehouses which carry that product. Then we find which stores subscribe to those warehouses and then finally figure out which stores are in the stateid provided from the form.

I hope this explains the mess.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 1st, 2006, 20:30
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Very Ugly SQL statement. Help Needed.

Whilst one could hopefully make an educated guess, I think it would be useful if you edited your original post and indicated primary, secondary and foreign keys.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
asp, sql

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ugly Dog Designs macman0295 Free Web Site Critique 3 Feb 5th, 2008 10:35
PHP If Statement... mcdanielnc89 PHP Forum 16 Dec 9th, 2007 17:44
If..Else statement help IanW PHP Forum 3 Oct 6th, 2006 13:40
Help with If Statement. JohnMitch Classic ASP 2 Jan 5th, 2005 01:05
With Statement Trebz Classic ASP 2 Feb 2nd, 2004 14:56


All times are GMT. The time now is 04:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42