Click here to Skip to main content
15,912,329 members
Home / Discussions / Database
   

Database

 
QuestionHow to fill null data in control froms in VB.Net Pin
rehan_cop19-Oct-06 7:09
rehan_cop19-Oct-06 7:09 
AnswerRe: How to fill null data in control froms in VB.Net Pin
Mairaaj Khan19-Oct-06 22:34
professionalMairaaj Khan19-Oct-06 22:34 
Questionselecting data for crystal reports Pin
haseeb_saeed18-Oct-06 21:14
haseeb_saeed18-Oct-06 21:14 
Questioncatching sql exception type Pin
DownBySpj18-Oct-06 21:01
DownBySpj18-Oct-06 21:01 
AnswerRe: catching sql exception type Pin
Colin Angus Mackay19-Oct-06 5:18
Colin Angus Mackay19-Oct-06 5:18 
AnswerRe: SQL error :Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.??? [help] Pin
Mike Dimmick19-Oct-06 6:51
Mike Dimmick19-Oct-06 6:51 
Questionhow to display daily sales between the date? [urgent] Pin
campbells18-Oct-06 18:58
campbells18-Oct-06 18:58 
AnswerRe: how to display daily sales between the date? [urgent] Pin
Edbert P19-Oct-06 15:25
Edbert P19-Oct-06 15:25 
Hmm...it's a bit hard to understand your query as it's too complicated.
You might want to simplify it a bit.
First, use IN instead of deptcode = 14 or deptcode = 15 and so on.

So let's format it first into:
SELECT t1.supermarket,t1.softline, t1.hardline, (t1.supermarket+t1.softline+ t1.hardline) AS TOTAL
FROM 
(SELECT (SELECT SUM(totalsales+returnamt) AS TotalSoft 
        FROM tot_item
        WHERE bizdate='2006-10-1' AND deptcode IN (11, 12, 13, 14, 15, 16, 17)) AS softline,

        (SELECT SUM(totalsales+returnamt) AS TotalHard 
        FROM tot_item
        WHEREbizdate='2006-10-1' AND deptcode IN (21, 22, 23, 24, 25, 26, 27, 28, 29)) AS hardline,

        (SELECT sum(totalsales+returnamt) AS TotalSupermarket 
        FROM tot_item
        WHERE bizdate='2006-10-1' AND deptcode IN (30, 40, 50, 60, 70, 80, 90)) AS supermarket
) AS t1 


Now that it's more simplified, I found that you can actually separate softline, hardline, and supermarket into 3 separate queries to save the confusion, and we can use GROUP BY to show the sum for each bizdate.

Query1:
SELECT bizdate, SUM(totalsales+returnamt) AS TotalSoft
FROM tot_item
WHERE deptcode IN (11, 12, 13, 14, 15, 16, 17)
GROUP BY bizdate

Query2:
SELECT bizdate, SUM(totalsales+returnamt) AS TotalHard
FROM tot_item
WHERE deptcode IN (21, 22, 23, 24, 25, 26, 27, 28, 29) AS hardline
GROUP BY bizdate

Query3:
SELECT bizdate, sum(totalsales+returnamt) AS TotalSupermarket
FROM tot_item
WHERE deptcode IN (30, 40, 50, 60, 70, 80, 90) AS supermarket
GROUP BY bizdate


Now in your final query you can link all the total using the following:
SELECT Query1.bizdate, TotalSoft, TotalHard, TotalSupermarket
FROM Query1
LEFT JOIN Query2 ON Query1.bizdate = Query2.bizdate
LEFT JOIN Query3 ON Query1.bizdate = Query3.bizdate


This will return your daily result of the sale.
From there you can specify the 15 days total sum.

If you want to put them all as one big query, here's the query:
SELECT Query1.bizdate, TotalSoft, TotalHard, TotalSupermarket
FROM (SELECT bizdate, SUM(totalsales+returnamt) AS TotalSoft 
        FROM tot_item
        WHERE deptcode IN (11, 12, 13, 14, 15, 16, 17)
        GROUP BY bizdate) AS Query1
LEFT JOIN (SELECT bizdate, SUM(totalsales+returnamt) AS TotalHard 
        FROM tot_item
        WHERE deptcode IN (21, 22, 23, 24, 25, 26, 27, 28, 29) AS hardline
        GROUP BY bizdate) AS Query2 
ON Query1.bizdate = Query2.bizdate
LEFT JOIN (SELECT bizdate, sum(totalsales+returnamt) AS TotalSupermarket 
        FROM tot_item
        WHERE deptcode IN (30, 40, 50, 60, 70, 80, 90) AS supermarket
        GROUP BY bizdate) AS Query3 
ON Query1.bizdate = Query3.bizdate


I hope the explanation above helps in your problem.
Note: I'm blind coding, so please check the syntax for me, ok Wink | ;)

Cheers,

Edbert

"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson

"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin

Edbert
Sydney, Australia

GeneralRe: how to display daily sales between the date? [urgent] Pin
campbells19-Oct-06 15:49
campbells19-Oct-06 15:49 
GeneralRe: how to display daily sales between the date? [urgent] Pin
Edbert P19-Oct-06 16:02
Edbert P19-Oct-06 16:02 
GeneralRe: how to display daily sales between the date? [urgent] Pin
Edbert P19-Oct-06 16:04
Edbert P19-Oct-06 16:04 
GeneralRe: how to display daily sales between the date? [urgent] Pin
campbells19-Oct-06 16:37
campbells19-Oct-06 16:37 
Questionsqlconnection Pin
avahia18-Oct-06 17:53
avahia18-Oct-06 17:53 
QuestionError I keep getting in my vb program (ADO error) Pin
MichaelDurham18-Oct-06 10:21
MichaelDurham18-Oct-06 10:21 
AnswerRe: Error I keep getting in my vb program (ADO error) Pin
Edbert P19-Oct-06 18:41
Edbert P19-Oct-06 18:41 
GeneralRe: Error I keep getting in my vb program (ADO error) Pin
MichaelDurham24-Oct-06 8:24
MichaelDurham24-Oct-06 8:24 
QuestionSlow performance in .NET? Pin
Xiangyang Liu 刘向阳18-Oct-06 4:10
Xiangyang Liu 刘向阳18-Oct-06 4:10 
AnswerRe: Slow performance in .NET? Pin
Ed.Poore19-Oct-06 13:36
Ed.Poore19-Oct-06 13:36 
GeneralRe: Slow performance in .NET? Pin
Xiangyang Liu 刘向阳20-Oct-06 17:26
Xiangyang Liu 刘向阳20-Oct-06 17:26 
GeneralRe: Slow performance in .NET? Pin
Ed.Poore21-Oct-06 8:04
Ed.Poore21-Oct-06 8:04 
QuestionHow to increase size of database in SQL Server 2000 Pin
prakash_21017-Oct-06 23:24
prakash_21017-Oct-06 23:24 
AnswerRe: How to increase size of database in SQL Server 2000 Pin
Mairaaj Khan18-Oct-06 0:12
professionalMairaaj Khan18-Oct-06 0:12 
GeneralRe: How to increase size of database in SQL Server 2000 Pin
Jerry Hammond18-Oct-06 10:09
Jerry Hammond18-Oct-06 10:09 
QuestionUsing dataset in a client-server application Pin
baxter_dev17-Oct-06 23:11
baxter_dev17-Oct-06 23:11 
AnswerRe: Using dataset in a client-server application Pin
Colin Angus Mackay17-Oct-06 23:17
Colin Angus Mackay17-Oct-06 23:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.