Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
thiyait
Yak Posting Veteran
70 Posts |
Posted - 2007-10-12 : 08:38:31
|
| I hope following both query does the same job but result will be differnt for me. can some one help me to explain the difference of two queryFirst query retrive the result as expected but second one didnt what is the problem.select HexPayCategoryElement.payelementid,HexPayCategoryElement.payelementid,res.calculatedvalue from HexPayCategoryElement HexPayCategoryElement,Hexpaycalculatedresult res whereHexPayCategoryElement.HRMPayrollCategoryID *= res.HRMPayrollCategoryID andHexPayCategoryElement.payelementid *= res.payelementid andHexPayCategoryElement.dataareaid *= res.dataareaid andHexPayCategoryElement.payelementtype *= res.payelementtype andres.dataareaid='glr'and res.HRMPayCalendarID = 'Month'and res.HRMPayPeriodId = 'Month001'and res.emplid = 'emp006'and HexPayCategoryElement.HRMPayrollCategoryID = 'Check' order by sequenceselect HexPayCategoryElement.payelementid,res.payelementid,res.calculatedvalue from HexPayCategoryElement HexPayCategoryElementleft outer join Hexpaycalculatedresult res on HexPayCategoryElement.HRMPayrollCategoryID =res.HRMPayrollCategoryIDand HexPayCategoryElement.payelementid=res.payelementidand HexPayCategoryElement.dataareaid=res.dataareaidand HexPayCategoryElement.payelementtype=res.payelementtypewhere res.dataareaid='glr'and res.HRMPayCalendarID = 'Month'and res.HRMPayPeriodId = 'Month001'and res.emplid = 'emp006'and HexPayCategoryElement.HRMPayrollCategoryID = 'Check' order by sequencethanks in advancethiya |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2007-10-12 : 09:04:00
|
| Is your problem in the second query that you are getting to many rows being returned. Using a Left Outer Join will preserve the unmatched rows on the left tableJack Vamvas--------------------Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL |
 |
|
|
thiyait
Yak Posting Veteran
70 Posts |
Posted - 2007-10-12 : 09:16:29
|
| First query retrive the followingMonth test1 987month test2 NULL(not in second table)Above is the correct onesecond retrive as follows:(here test2 should come in the result)Month test1 987 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-12 : 09:26:59
|
[code]select HexPayCategoryElement.payelementid, res.payelementid, res.calculatedvaluefrom HexPayCategoryElementleft join Hexpaycalculatedresult as res on res.HRMPayrollCategoryID = HexPayCategoryElement.HRMPayrollCategoryID and res.payelementid = HexPayCategoryElement.payelementid and res.dataareaid = HexPayCategoryElement.dataareaid and res.payelementtype = HexPayCategoryElement.payelementtype and res.dataareaid = 'glr' and res.HRMPayCalendarID = 'Month' and res.HRMPayPeriodId = 'Month001' and res.emplid = 'emp006'where HexPayCategoryElement.HRMPayrollCategoryID = 'Check'order by {table name or alias here}.sequence[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
|
|
|
|