Print Page | Close Window

Sql Problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=15798
Printed Date: 29 March 2026 at 7:40pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Sql Problem
Posted By: Phat
Subject: Sql Problem
Date Posted: 12 July 2005 at 6:26am
Is there any sql guru's out there?

If so can you let me know if it is possible to do the following:

SELECT tblSector.Sector, Sum(tblBuy.tempValue) AS SumOftempValue, Sum(tblBuy.TotalCost) AS SumOfTotalCost" & _
                &n bsp;           " FROM ((tblBuy INNER JOIN tblInstruments ON tblBuy.Instrument_ID = tblInstruments.Instrument_ID) INNER JOIN tblCodes ON tblBuy.Code_ID = tblCodes.Code_ID) LEFT JOIN tblSector ON tblCodes.Sector_ID = tblSector.Sector_ID" & _
                &n bsp;           " Where (((tblBuy.TradeOpen) = True)) GROUP BY tblSector.Sector;"

In the above sql SumOftempValue can have a null value and whenit does I want the sql to use SumOfTotalCost.

So if SumOftempValue = null then SumOfTotalCost. Can this be in one field in the sql so i do not need to check it in the code?

Any idea? Does it make sense?




-------------
http://buildit.sitesell.com/sitebuildithome.html - Get a website that sells



Replies:
Posted By: michael
Date Posted: 14 July 2005 at 10:47am
SELECT  tblSector.Sector,
 IsNull(Sum(tblBuy.tempValue),Sum(tblBuy.TotalCost)) AS SumOftempValue,
 Sum(tblBuy.TotalCost) AS SumOfTotalCost
FROM  ((tblBuy INNER JOIN tblInstruments ON tblBuy.Instrument_ID = tblInstruments.Instrument_ID)
  INNER JOIN tblCodes ON tblBuy.Code_ID = tblCodes.Code_ID) LEFT JOIN tblSector ON tblCodes.Sector_ID = tblSector.Sector_ID
Where (((tblBuy.TradeOpen) = True))
GROUP BY tblSector.Sector

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net