SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : The Server :

Previous DiscussionNext Discussion
 subquries and programming in ms sql2k

i'm trying to create a sql statement that will feed a report.  it will pull from 3 tables.  to get the exact data i need, 1 of the tables i'm pulling data from is hit 3 times. 

Here is the code that I have so far:

SELECT Sec.[user_id], Sec.exp_date, Cus.first_name, Cus.last_name, Cus.type,

(SELECT COUNT (a_id)
FROM db_action.dbo.action
WHERE owner_id = Sec.[user_id]
AND date_created > {ts '2005-01-01 00:00:00'}
AND date_created < {ts '2005-10-19 00:00:00'} ) AS activitycounter,

(SELECT count(chart_id)
FROM db_info.dbo.tbl_charts
WHERE customer_id = Sec.[user_id])AS total_tasks,

(SELECT COUNT(chart_id)
FROM db_info.dbo.tbl_charts
WHERE task_status = 'not applicable'
AND customer_id = Sec.[user_id]) AS not_applicable ,

(SELECT COUNT(chart_id)
FROM db_info.dbo.tbl_charts
WHERE task_status = 'completed'
AND customer_id = Sec.[user_id]) AS total_completed

FROM db_sec.dbo.tbl_security AS Sec
INNER JOIN db_client.dbo.tbl_customerprofile AS Cus
ON Cus.customer_id = Sec.[user_id]
WHERE Sec.area_id = 29
AND Sec.exp_date like '%-Oct-05%'
AND Sec.[permissions] = 'y'
ORDER BY Sec.[user_id]

As is expected, this code works, no problems.  Now I just need to do some math on these results. 

(total_completed / (total_tasks - not_applicable)) * 100

That is to say, take the result of total_task, subtract not applicable, with what remains, divide that by the result in total_completed and with that multiply it by 100.
Finding percentage

so, i can do that by modifying my query like this

SELECT Sec.[user_id], Sec.exp_date, Cus.first_name, Cus.last_name, Cus.type,

(SELECT COUNT (a_id)
FROM db_action.dbo.action
WHERE owner_id = Sec.[user_id]
AND date_created > {ts '2005-01-01 00:00:00'}
AND date_created < {ts '2005-10-19 00:00:00'} ) AS activitycounter,

(SELECT COUNT(chart_id)
FROM db_info.dbo.tbl_charts
WHERE task_status = 'completed'
AND customer_id = Sec.[user_id])/
((SELECT count(chart_id)
FROM db_info.dbo.tbl_charts
WHERE customer_id = Sec.[user_id]) -
(SELECT COUNT(chart_id)
FROM db_info.dbo.tbl_charts
WHERE task_status = 'not applicable'
AND customer_id = Sec.[user_id])) *100 ,

FROM db_sec.dbo.tbl_security AS Sec
INNER JOIN db_client.dbo.tbl_customerprofile AS Cus
ON Cus.customer_id = Sec.[user_id]
WHERE Sec.area_id = 29
AND Sec.exp_date like '%-Oct-05%'
AND Sec.[permissions] = 'y'
ORDER BY Sec.[user_id]

Now the problem is that occasionally in the subtration, the result of the subtraction is 0.  Then when i take it to the division portion, it throws everything off. 

What I'd like to write logic to do is that when ever during the subtraction it finds the result to be 0, that it in fact not divide and just declare the result 0

If anybody can't point me in the right direction, it would be greatly appreciaated.

-m

Started By mindjuju on Oct 20, 2005 at 12:40:05 PM

3 Response(s) | Reply

Earlier Replies | Replies 1 to 3 of 3 | Later Replies
mindjuju on Oct 20, 2005 at 4:42:48 PM (# 1)

nevermind, i figured out how to do it. 

put the whole thing in a stored procedure

do the selects into a temp table

run a select on the temp table with a case

m


kkarthikeyankrr on Jun 26, 2007 at 5:01:13 AM (# 2)

Hi anyone can help me in web services security.I have written the code for XML encryption and decryption.

In web services we are not sending the request as an XML.Internally our request will be converted to XML format.In this situation how can i get that xml input and where i have to use my encryption code.Its very urgent can any1 help me to solve this problm?

Regards

K.Karthikeyan

  


MHenke on Jun 26, 2007 at 10:58:55 PM (# 3)

Hijacker


Earlier Replies | Replies 1 to 3 of 3 | Later Replies

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.