a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

SQL query problem

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> SQL query problem
Page: [1]
 
adam2804

 

Posts: 34
Joined: 6/6/2006
Status: offline

 
SQL query problem - 6/29/2006 11:05:39   
Any takers to this one? It's doing my head in

SELECT     w.WorkType, t.Description, p.Unit, CAST(ROUND(p.Price, 2) AS MONEY) AS Price, CONVERT(CHAR, CEILING
                          ((SELECT     SUM(Quantity)
                              FROM         WorkDetails W
                              WHERE     JobNumber = P.ID AND W.WorkType = ISNULL(P.BillUsing, P.WorkType)))) AS Quantity, CONVERT(VARCHAR, CAST
                          ((SELECT     SUM(Hours)
                              FROM         WorkDetails W
                              WHERE     JobNumber = P.ID AND W.WorkType = ISNULL(P.BillUsing, P.WorkType)) / 24 AS DATETIME), 108) AS Hours, CONVERT(CHAR, 
                      CAST((b.QuantityMultiplier *
                          (SELECT     SUM(Quantity)
                            FROM          WorkDetails W
                            WHERE      JobNumber = P.ID AND W.WorkType = ISNULL(P.BillUsing, P.WorkType)) + b.TimeMultiplier *
                          (SELECT     SUM(Hours)
                            FROM          WorkDetails W
                            WHERE      JobNumber = P.ID AND W.WorkType = ISNULL(P.BillUsing, P.WorkType))) * p.Price / p.Unit AS MONEY)) AS TotalPrice, 
                      b.Description AS Billing, p.ID, p.BillUsing
FROM         WorkDetails w INNER JOIN
                      TB_MasterPrices p ON w.JobNumber = p.ID AND w.WorkType = p.WorkType INNER JOIN
                      WorkType t ON p.WorkType = t.WorkType INNER JOIN
                      TB_Billing b ON p.Billing_ID = b.ID
WHERE     (w.JobNumber = '58610')
GROUP BY w.WorkType, t.Description, p.Unit, p.Price, b.Description, p.ID, p.BillUsing, p.WorkType, b.TimeMultiplier, b.QuantityMultiplier, p.ID, w.JobNumber


The problem I'm having is with the Quantity, Hours & TotalPrice columns where the resulting table doesn't work if there is a null result. However, it should work. Anything that looks obviously wrong?
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: SQL query problem - 6/29/2006 12:04:36   
quote:

I'm having is with the Quantity, Hours & TotalPrice columns where the resulting table doesn't work if there is a null result. However, it should work.


Most times Nulls will *not* work in normal calculations since they are not numeric and cannot be directly converted as such.

Are they number fields in the DB? There should be no Nulls if that is the case. By design, any fields that I am going to perform Math on, I never allow Nulls.

Of course hind sight is 20/20 isn't it. Could you run an UPDATE to change Nulls to 0?

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to adam2804)
adam2804

 

Posts: 34
Joined: 6/6/2006
Status: offline

 
RE: SQL query problem - 6/29/2006 12:17:27   
Thanks RDouglass

The weird thing is the values that they are trying to calculate are populated, and numeric. The query works for another record on the db..... I think it may have something to do with the 'WorkTypes' trying to convert these to numeric (as these can be 01, 02, etc or A3, R4, etc) have you had any experience of this and how you have resolved it if you have had?

Thanks

Adam

(in reply to rdouglass)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: SQL query problem - 6/29/2006 12:54:54   
quote:

etc or A3, R4,


Obviously you can't do math on those. I wouldn't even attempt to figure out how to do it. It wouldn't be any math I'm familiar with.

Why would you need to calculate this value? Or are you lookng at counts? That query looks too deep for me to delve into too much at the moment but if it's record specific, what is different between a record that works and one that doesn't? Is it the Nulls or is it chars in a field you want to calculate?

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to adam2804)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> ASP and Database >> SQL query problem
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts