Home > Archive > SQL server exams > October 2002 > Coco's Question of the Week #15





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Coco's Question of the Week #15
cocolocopolo

2002-10-19, 12:07 am

RE: Syntax Error

I Got error from the following statement:

Update Products Set UnitPrice = UnitPrice * 0.9
Where ProductID = (Select Top 10 ProductID From Products Order by UnitPrice Desc)

Please help where I made mistake.

Thanks.
2lazybutsmart

2002-10-19, 4:28 am

lemme put ur query in english.

update the products table. set the unitprice to the current unitprice * 0.9. where the productid equals to one of the following (get me the top 10 product id's from the products table with the largest values (do this by ordering them in a descending manner)).

If this is what u intend to do, then you have to replace the where clause with the following

---------------------------------
Where ProductID IN (Select Top 10 ProductID From Products Order by UnitPrice Desc)
-----------------------------------

Your previous query would return the following error:

---------------------------------------
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
--------------------------------------------

the '=' sign referes to one value. the IN keyword chooses between multiple values. since your query return 10 rows, an equal sign would not work.


cheers,
2lazybutsmart
cocolocopolo

2002-10-20, 12:50 am

Wow!!

Thanks dear 2lazybutsmart.

Now I understand the '=' sign cannot be used if the query is going to return multiple value.

Thanks again.
2lazybutsmart

2002-10-20, 7:51 am

What's so 'WOW!' about it coco?
cocolocopolo

2002-10-20, 11:49 pm

Dear 2lazybutsmart:

I 'wow' because you are really the dictionary.
2lazybutsmart

2002-10-21, 3:25 pm

coco, do u mind if you tell us a little about your IT life?
cocolocopolo

2002-10-24, 2:06 pm

Dear 2lazybutsmart:

Sure I like to have your advice.

Please keep in mind following:

1. You already know I am a big boy (58 years of age).

2. English is my second language. When I
came to USA, I was 35 years old. I brought
with me a dictionary (which I bought around
1962 when I was first year in Senior High
scholl).

3. I still have hard time in English and
learn very slow.

Appreciate any advice you have for me.
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net