SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 2nd, 2004, 10:26 AM
plasma800 plasma800 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Houston
Posts: 407 plasma800 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 13 m 36 sec
Reputation Power: 5
Send a message via Yahoo to plasma800
SQL Statement Case selection...

Continuation from this post http://forums.aspfree.com/t26343/s.html

Trying to determine a price range, based on 3 columns of prices. Simply trying to get THE lowest price offered for an item and the highest price offered for an item, and the item is offered by multiple vendors.

This post above is very long and this is a contuation of memnochs suggestion, whichs sounds wonderful, but I'm having trouble getting the select statement to run..

This selection is in the middle of another loop running through products. I've tried putting the statement through QA, but dont know enough about it to evaluate the statements and errors from QA.

k so.. here goes. table queried is called ttInventory, looking at 3 columns, newprice, refurbprice and oosprice (basically new used and out of service) some fields are filled with a 0.00 (if vendor does not have part used..or new..or what have you.

here's mem's select statement.

Code:
Dim rangeRs, maxPrice, minPrice, SQL
set rangeRS = Server.CreateObject("ADODB.Recordset")

SQL = "SELECT" &_
SQL = SQL & "Case" &_
SQL = SQL & "When newprice > refurbprice AND newprice > oosprice Then newprice" &_
SQL = SQL & "When refurbprice > newprice AND refurbprice > oosprice THEN refurbprice" &_
SQL = SQL & "When oosprice > newprice AND oosprice > refurbprice THEN oosprice" &_
SQL = SQL & "End As 'maxPrice'" &_
SQL = SQL & "Case" &_
SQL = SQL & "When newprice < refurbprice AND newprice < oosprice Then newprice" &_
SQL = SQL & "When refurbprice < newprice AND refurbprice < oosprice THEN refurbprice" &_
SQL = SQL & "When oosprice < newprice AND oosprice < refurbprice THEN oosprice" &_
SQL = SQL & "End As 'minPrice'" &_
SQL = SQL & "FROM ttInventory WHERE prodID = '" & itemRs("prodId") & "'"
rangeRs.open SQL, objCn, 3, 3


When I run the statement online in a browser, it returns :

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/itemlist.asp, line 110

line 110 = rangeRs.open SQL, objCn, 3, 3
---------------------------------
IN QA I ran the statement as so..
Code:
SELECT
Case
When newprice > refurbprice AND newprice > oosprice Then newprice
When refurbprice > newprice AND refurbprice > oosprice THEN refurbprice
When oosprice > newprice AND oosprice > refurbprice THEN oosprice
End As 'maxPrice'
Case
When newprice < refurbprice AND newprice < oosprice Then newprice
When refurbprice < newprice AND refurbprice < oosprice THEN refurbprice
When oosprice < newprice AND oosprice < refurbprice THEN oosprice
End As 'minPrice'
FROM ttInventory WHERE prodID = '" & itemRs("prodId") & "'

and it returned :
Server: Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'Case'.

line 7 being the second instance of the word CASE

so i ran again in QA as
Code:
SELECT
Case
When newprice > refurbprice AND newprice > oosprice Then newprice
When refurbprice > newprice AND refurbprice > oosprice THEN refurbprice
When oosprice > newprice AND oosprice > refurbprice THEN oosprice
End As maxPrice
FROM ttInventory where prodID='1'

and it returned
maxPrice
----------
145.00
147.00

(2 row(s) affected)

Any ideas on why i would get the arguments error... or anything else for that matter.. Im graspin
Attached Files
File Type: txt itemlist.txt (7.6 KB, 205 views)

Reply With Quote
  #2  
Old May 4th, 2004, 06:13 AM
rohulsan rohulsan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 rohulsan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try This
--------------------
SELECT
Case
When newprice > refurbprice AND newprice > oosprice Then newprice
When refurbprice > newprice AND refurbprice > oosprice THEN refurbprice
When oosprice > newprice AND oosprice > refurbprice THEN oosprice
End As 'maxPrice',
Case
When newprice < refurbprice AND newprice < oosprice Then newprice
When refurbprice < newprice AND refurbprice < oosprice THEN refurbprice
When oosprice < newprice AND oosprice < refurbprice THEN oosprice
End As 'minPrice'
FROM ttInventory WHERE prodID = '" & itemRs("prodId") & "'
-------------------

Try "," Before second case.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > SQL Statement Case selection...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT