?
Solved

SQL Script

Posted on 2009-04-30
5
Medium Priority
?
193 Views
Last Modified: 2012-05-06
I am trying to Show all books that are both cheaper than the most expensive poetry book, and more expensive than the cheapest poetry book.  Any idea?


I am trying this code
 
DECLARE @M int;
DECLARE @L int;
SELECT @M = MAX(BKListPrice)
SELECT @L = MIN(BKListPrice)
from tblbooks
WHERE TopicCode = 'Poe'
 
 
 
SELECT BKTitle, BKListprice
FROM tblbooks
WHERE BKListPrice < @M
WHERE BKListPrice > @L
 
GO

Open in new window

0
Comment
Question by:iolike
  • 3
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24267640
close enough
 
DECLARE @M int;
DECLARE @L int;
SELECT @M = MAX(BKListPrice)
   , @L = MIN(BKListPrice)
from tblbooks
WHERE TopicCode = 'Poe'
 
 
 
SELECT BKTitle, BKListprice
FROM tblbooks
WHERE BKListPrice < @M
WHERE BKListPrice > @L
 

Open in new window

0
 
LVL 1

Accepted Solution

by:
FatEric13 earned 2000 total points
ID: 24267691
One more mistake:



DECLARE @M int;
DECLARE @L int;
SELECT @M = MAX(BKListPrice)
, @L = MIN(BKListPrice)
from tblbooks
WHERE TopicCode = 'Poe'
 
SELECT BKTitle, BKListprice
FROM tblbooks
WHERE BKListPrice < @M
AND BKListPrice > @L

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24267807
glad we could help...

iolike,
  note that I posted exactly the same 12 minutes earlier (unless I did not see someting),
  so it should have been at least a split to be fair!

  I will NOT complain, but others might do so, please double-check next times!

FatEric13,
  welcome on EE, congrats for your first Experts Points!
  hope to see you around with more good answers!
 
Cheers
0
 
LVL 1

Expert Comment

by:FatEric13
ID: 24267929
Thanks angellll.

Glad i could help.

I your snippet of the code, there was still a little mistake... The 'where' must be replaced with an 'and' in the select. (you can only have one where).

SELECT BKTitle, BKListprice
FROM tblbooks
WHERE BKListPrice < @M
WHERE BKListPrice > @L
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24267980
I see, I really skipped that!
good catch!
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question