Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Get the active ship data
- UPDATE
- #ship_stats
- SET
- actives = COUNT(*),
- duras = SUM(fc.durability)
- FROM
- crawler_flsCombatant fc
- WHERE
- cluster_id = fc.clusterID AND
- ship_name = fc.deedName
- -- First of all, you have aggregates in an update statement which doesn't quite make sense
- -- Also, I try not to write sql without aliasing the tables
- -- So the intermediate (still invalid) form would apparently be:
- -- ps yo' style is uggs
- UPDATE ss
- SET ss.actives = COUNT(*),
- ss.duras = SUM(fc.durability)
- FROM #ship_stats ss
- inner join crawler_flsCombatant fc on fc.clusterID = ss.cluster_id
- and fc.deedName = ss.ship_name
- -- but of course, aggregates in the update still
- -- a couple ways to approach this, the simplest is just subqueries
- -- without actually an instance of sql server to test this, I think it's correct
- update ss set ss.actives = (select count(*)
- from crawler_flsCombatant fc
- where fc.cluster_id = ss.cluster_id
- and fc.deedName = ss.ship_name),
- ss.duras = (select sum(fc.durability)
- from crawler_flsCombatant fc
- where fc.cluster_id = ss.cluster_id
- and fc.deedName = ss.ship_name)
- from #ship_stats ss
Add Comment
Please, Sign In to add comment