Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Problem with quiry

Author  Topic 

tgra
Starting Member

1 Post

Posted - 2002-11-15 : 20:05:03
Hello!

I have a datbase called Booking. It is a bookingsystem for cabins..

I try to calculate the price per night using Bestilling (order) and Hytter (cabins) like this:

"

IF
(3 <= (SELECT Bestilling.Ankomst, Bestilling.Avreise,
(DATEDIFF(day, Ankomst, Avreise))
FROM Bestilling)
)
BEGIN
(SELECT Bestilling.*,Hytter.*,
(DATEDIFF(day, Ankomst, Avreise))*PrisPerDag AS [Å Betale]
FROM Bestilling INNER JOIN Hytter
ON Bestilling.Hyttenummer = Hytter.IDHyttenummer
)
END

ELSE
BEGIN
(SELECT Bestilling.*,Hytter.*,
(DATEDIFF(day, Ankomst, Avreise))*PrisMangeDager AS [Å Betale]
FROM Bestilling INNER JOIN Hytter
ON Bestilling.Hyttenummer = Hytter.IDHyttenummer
)
END
"

I get this error:

"
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
"

Could nybode help me?

Thanks alot in advance!

Best regards Thomas...

burbakei
Yak Posting Veteran

80 Posts

Posted - 2002-11-15 : 21:28:02
the query
(SELECT Bestilling.Ankomst, Bestilling.Avreise,
(DATEDIFF(day, Ankomst, Avreise))
FROM Bestilling)

might return more than one record and you can not comapre with for example 3. and when you want to compare something like 3 with the result of a query there must be one column in the select list.

you can write:

IF EXISTS(SELECT *
FROM Bestilling
WHERE DATEDIFF(day, Ankomst, Avreise) >= 3)
BEGIN
...


Go to Top of Page
   

- Advertisement -