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
 General SQL Server Forums
 New to SQL Server Programming
 Cannot perform an aggregate function on an express

Author  Topic 

gruesomeguy
Starting Member

1 Post

Posted - 2007-12-27 : 19:13:14
SELECT((datediff("d", arrival,departure)) - ((select case when datediff("d", arrival, '07/24/07') < 0 then
(select case when datediff("d", '07/27/07',departure) < 0 then 0 else datediff("d", '07/27/07',departure) end)
else datediff("d", arrival, '07/24/07') end)) as nights

does any one know how can i sum the nights

right now the error is
Server: Msg 130, Level 15, State 1, Line 4
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

nr
SQLTeam MVY

12543 Posts

Posted - 2007-12-27 : 19:38:44
SELECT datediff("d", arrival,departure)
- case when datediff("d", arrival, '07/24/07') < 0 then
case when datediff("d", '07/27/07',departure) < 0 then 0
else datediff("d", '07/27/07',departure
end
else datediff("d", arrival, '07/24/07')
end as nights


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -