Author |
Topic |
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-17 : 03:30:18
|
I have output of two queriesFirst Query OutPutGDate mNoSecond Query OutPutGDate wNoI've to show the output likeGDate mNo wNoHow could I combine these columnsVB6/ASP.NET------------------------http://www.nehasoftec.com |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-04-17 : 03:40:10
|
[code]SELECT *FROM( < ..Q1.. >) as Q1INNER JOIN( < ..Q2.. >) as Q2 ON Q1.GDate = Q2.GDate[/code]if you have mismatch gdate, then you might need to use outer join KH[spoiler]Time is always against us[/spoiler] |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-04-17 : 03:40:27
|
Is the number of rows same for both the queries? Look for Cross-tab or PIVOTMadhivananFailing to plan is Planning to fail |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-17 : 04:23:43
|
quote: Originally posted by khtan
SELECT *FROM( < ..Q1.. >) as Q1INNER JOIN( < ..Q2.. >) as Q2 ON Q1.GDate = Q2.GDate if you have mismatch gdate, then you might need to use outer join KH[spoiler]Time is always against us[/spoiler]
Doesn't worksBoth the queries comes from different tablesVB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-17 : 04:27:11
|
quote: Originally posted by madhivanan Is the number of rows same for both the queries? Look for Cross-tab or PIVOTMadhivananFailing to plan is Planning to fail
I think you are correct. Should use Piot table. Can u post some links or solution for my query.ThanxVB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-04-17 : 05:37:55
|
<<Doesn't worksBoth the queries comes from different tables>>What di you mean by "Doesn't work?". Do both the queries return the column GDate?MadhivananFailing to plan is Planning to fail |
 |
|
vinu.vijayan
Posting Yak Master
227 Posts |
Posted - 2012-04-17 : 07:48:48
|
Are the GDate values returned from both the tables same??....Please post the result sets of both the queries...Life could be a lot easier if you did so.N 28° 33' 11.93148"E 77° 14' 33.66384" |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-17 : 20:02:26
|
quote: Originally posted by madhivanan <<Doesn't worksBoth the queries comes from different tables>>What di you mean by "Doesn't work?". Do both the queries return the column GDate?MadhivananFailing to plan is Planning to fail
First Query Return :GDate mNo2011-01-31 00:00:00 52011-02-01 00:00:00 152011-05-12 00:00:00 52011-05-13 00:00:00 4Second Query Return :GDate wNo2011-02-01 00:00:00 32011-02-02 00:00:00 12011-05-12 00:00:00 82011-05-18 00:00:00 92011-05-22 00:00:00 6I've to show output likeGDate mNo wNo2011-01-31 00:00:00 5 02011-02-01 00:00:00 15 32011-05-12 00:00:00 5 82011-05-13 00:00:00 4 02011-05-18 00:00:00 9 02011-05-22 00:00:00 6 0VB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-04-17 : 21:34:05
|
Can you also show us the query that you tried that "Doesn't works" ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-18 : 02:37:18
|
quote: Originally posted by khtan Can you also show us the query that you tried that "Doesn't works" ? KH[spoiler]Time is always against us[/spoiler]
My querySELECT *FROM( Select Cast(convert(Char(11),a.LogDate,113) as datetime) as GenDate, COUNT(a.scratchno) as TotalPinsfrom ScratchMast a where OwnerID = 1669 and genDate >=@FirstDate and GenDate <= @SecondDate and LogDate is not null group by Cast(convert(Char(11),a.LogDate,113) as datetime) ) as Q1INNER JOIN(Select vdate as GenDate, COUNT (*) as TotalPins from IncExpMast b Where Part ='PIN FROM EWALLET' group by VDate ) as Q2 ON Q1.GenDate = Q2.GenDate It shows the data of those dates only which are commonmeans if first and second query has the data of 01 jan thenonly it shows data. It doesn't shows data of uncommon dates.kindly see my outputVB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-04-18 : 03:00:53
|
quote: Originally posted by khtanif you have mismatch gdate, then you might need to use outer join
Change your join to FULL OUTER JOIN KH[spoiler]Time is always against us[/spoiler] |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-18 : 09:19:13
|
quote: Originally posted by khtan
quote: Originally posted by khtanif you have mismatch gdate, then you might need to use outer join
Change your join to FULL OUTER JOIN KH[spoiler]Time is always against us[/spoiler]
Explain plzVB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-18 : 09:27:03
|
quote: Originally posted by khtan
quote: Originally posted by khtanif you have mismatch gdate, then you might need to use outer join
Change your join to FULL OUTER JOIN KH[spoiler]Time is always against us[/spoiler]
Oh Thanx! It solved my issue.....VB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-19 : 01:26:43
|
quote: Originally posted by khtan
quote: Originally posted by khtanif you have mismatch gdate, then you might need to use outer join
Change your join to FULL OUTER JOIN KH[spoiler]Time is always against us[/spoiler]
Now the headache is to show date in only 1 column.VB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-19 : 01:34:52
|
use SELECT COALESCE(Q1.GenDate,Q2.GenDate) AS GenDate,COALESCE(Q1.TotalPins,0) + COALESCE(Q2.TotalPins,0) AS TotalPinsFROM(Select Cast(convert(Char(11),a.LogDate,113) as datetime) as GenDate, COUNT(a.scratchno) as TotalPinsfrom ScratchMast a where OwnerID = 1669 and genDate >=@FirstDate and GenDate <= @SecondDate and LogDate is not nullgroup by Cast(convert(Char(11),a.LogDate,113) as datetime) ) as Q1FULL OUTER JOIN(Select vdate as GenDate, COUNT (*) as TotalPins from IncExpMast b Where Part ='PIN FROM EWALLET' group by VDate ) as Q2 ON Q1.GenDate = Q2.GenDate ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-04-19 : 02:41:58
|
quote: Originally posted by visakh16 use SELECT COALESCE(Q1.GenDate,Q2.GenDate) AS GenDate,COALESCE(Q1.TotalPins,0) + COALESCE(Q2.TotalPins,0) AS TotalPinsFROM(Select Cast(convert(Char(11),a.LogDate,113) as datetime) as GenDate, COUNT(a.scratchno) as TotalPinsfrom ScratchMast a where OwnerID = 1669 and genDate >=@FirstDate and GenDate <= @SecondDate and LogDate is not nullgroup by Cast(convert(Char(11),a.LogDate,113) as datetime) ) as Q1FULL OUTER JOIN(Select vdate as GenDate, COUNT (*) as TotalPins from IncExpMast b Where Part ='PIN FROM EWALLET' group by VDate ) as Q2 ON Q1.GenDate = Q2.GenDate ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Really, Thanx a lotVB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-19 : 08:50:50
|
wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|