Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my asp.net+vb web with accessdatabase. Have query web page in which calculation is made.
VB
SELECT AUTH.company
    ,AUTH.Auth
    ,Count(AUTH.company) AS Held
    ,(AUTH.Auth - Count(AUTH.company)) as [Sur/Defi]
FROM pers INNER JOIN AUTH ON pers.company = AUTH.company
GROUP BY AUTH.company,AUTH.Auth


The calculation is correct for those company in which persons are appointed

But if the person is not posted and even the company's auth is there then that names are not reflected in this web page. eg:_
SQL
Comapany            Auth     

Tata                12

and no one is posted in this company then this company name is not refelected

The company names should come even if there is no one posted in it as
SQL
Comapany            Auth         Held               Sur/Defi     

Tata                12             0                     12

and i want to add one more clause. There is a table named post and the field name in that is company (in this table transfers are entered).

i want one more calculation alongwith the above query is if transters are entered in post table then they should reflect as OUT in girdview .

My coding is in VB
Posted
Updated 7-Aug-13 17:29pm
v2

1 solution

If I understand you correctly, all you need to do is switch your JOIN:
SQL
SELECT AUTH.company
    ,AUTH.Auth
    ,Count(AUTH.company) AS Held
    ,(AUTH.Auth - Count(AUTH.company)) as [Sur/Defi]
FROM AUTH LEFT OUTER JOIN pers ON pers.company = AUTH.company
GROUP BY AUTH.company,AUTH.Auth

I don't quite understand the part about the transfers, need more info.
 
Share this answer
 
Comments
baijuep1970 7-Aug-13 12:36pm    
There is one more table (Post) i want to join that table also to this query. Count(pers.company=post.company) as out
but i am not able to join it
the logic is all unit from Auth.unit should display in my gridview
woopsydoozy 7-Aug-13 13:07pm    
I'm still not getting it. You seem to need some basic SQL training--try http://www.w3schools.com/sql/default.asp, and get into your DB manager and just keep tweaking your query until you get the result you want. Sounds like you're looking for another JOIN, likely something like this: AUTH LEFT OUTER JOIN pers ON pers.company = AUTH.company LEFT OUTER JOIN Post ON pers.company = Post.company. The data you want from the post table, I still don't see--are you trying to get a count of the people at that company, or the number of transfers, or ...? And where does unit come in?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900