Solved

# SQL Script

Posted on 2009-04-30
Medium Priority
193 Views
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
``````
0
Question by:iolike
• 3
• 2

LVL 143

Expert Comment

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

``````
0

LVL 1

Accepted Solution

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
``````
0

LVL 143

Expert Comment

ID: 24267807

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

ID: 24267929
Thanks angellll.

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

ID: 24267980
I see, I really skipped that!
good catch!
0

## Featured Post

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…