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 |
|
manikandan
Starting Member
35 Posts |
Posted - 2002-08-30 : 07:53:03
|
| Following syntax is acceptable in sybase and the query gives the expected result. What is the equivalent SQL query SELECT Org1.OrganizationDescription, Org1.OrganizationDescription, Org2.OrganizationDescription, EA.EMailAddress FROM Organization Org1, Organization Org2, OrganizationRelationship ORel, EMailAddress EA, EMailObject eO WHERE EA.resourceid = Org1.organizationid and EA.emailaddresstype = 'SMTP' and EA.PrimaryResourceAddress = 'Y' and EA.ResourceType = 'Organization' and eO.EMailObjectType <> 'Distrib List' and eO.EMailObjectType <> 'Public List Sec' and EA.EMailType = eO.EMailType and EA.EMailSite = eO.EMailSite and EA.MailBoxID = eO.MailBoxID and Org1.OrganizationID *= ORel.ChildOrganizationID and Org2.OrganizationID =* ORel.ParentOrganizationID and ORel.OrganizationRelationshipType = 'Home Cost Center' and Org1.OrganizationType NOT IN ('Conference Room', 'Private Room', 'Equipment')CheersManikandan |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-08-30 : 09:34:45
|
| replace the *= with left outer joinOrganization Org1 left outer join OrganizationRelationship ORelon Org1.OrganizationID = ORel.ChildOrganizationIDleft outer join Organization Org2on Org2.OrganizationID = ORel.ParentOrganizationIDjoin EMailAddress EAon EA.resourceid = Org1.organizationid andEA.emailaddresstype = 'SMTP' and EA.PrimaryResourceAddress = 'Y' and EA.ResourceType = 'Organization'join EMailObject eOonEA.EMailType = eO.EMailType and EA.EMailSite = eO.EMailSite and EA.MailBoxID = eO.MailBoxID and eO.EMailObjectType <> 'Distrib List' and eO.EMailObjectType <> 'Public List Sec'whereORel.OrganizationRelationshipType = 'Home Cost Center' and Org1.OrganizationType NOT IN ('Conference Room', 'Private Room', 'Equipment') *= is valid in sql server but a *= b *= c isn't - but can be done with this syntax.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
manikandan
Starting Member
35 Posts |
Posted - 2002-08-31 : 04:54:40
|
| Thanks for the reply.But some problems are there. The number of record that is returned by sybase is different from that SQL. (i did a DTS from Sybase to SQL) and ran these queries.i understand the syntatical problems in the query which i've sent.Until this point the query works.SELECT Org1.OrganizationDescription, Org1.OrganizationDescription, Org2.OrganizationDescription, EA.EMailAddress FROM Organization Org1, Organization Org2, OrganizationRelationship ORel, EMailAddress EA, EMailObject eO WHERE EA.resourceid = Org1.organizationid and EA.emailaddresstype = 'SMTP' and EA.PrimaryResourceAddress = 'Y' and EA.ResourceType = 'Organization' and eO.EMailObjectType <> 'Distrib List' and eO.EMailObjectType <> 'Public List Sec' and EA.EMailType = eO.EMailType and EA.EMailSite = eO.EMailSite and EA.MailBoxID = eO.MailBoxID and Org1.OrganizationID *= ORel.ChildOrganizationID .But after this point, the original query does a right outer join with Orel. From what i understand, sybase will consolidate the result sets until now and do a right outerjoin with ORel table. *= orel.childorganizationidWon't the result set be affected by doing a left outerjoin with org2 table. (i mean by doing a right outer join, null will be inserted on those columns on the left hand side, if it does not have any matching record with the right table. Will it be the same if you do a left outer join with the other table like what you have done here).My SQL knowledge is very limited. I could be completely wrong here. Please tell me on where i am erring and also i find problems in the where and on clause.These two conditions are included in the where clause.ORel.OrganizationRelationshipType = 'Home Cost Center' and Org1.OrganizationType NOT IN ('Conference Room', 'Private Room', 'Equipment') Shouldn't it be included in the on clause. If it is a inner join it is not a problem. But being a outer join, the result set will have an impact on including this in the where clause instead of On clause.If anyone could come up with a set of rules that needs to be followed while moving from old syntax to new syntax, it will be wonderful. And if someone could solve this query also, it will be very very useful.Thanks cheersmanikandanCheersManikandan |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-09-02 : 08:28:30
|
| you haveOrg1 *= ORelOrg2 =* ORelwhich should be the same asOrg1 *= ORelORel *= Org2which should be the same as Org1 left outer join ORelleft outer join Org2the problem probably comes from whether filter clauses are included in the join or the where clausea left outer join b on a.id = b.id and b.fld = 1this gives all rows from a and rows from b where b.fld = 1a left outer join b on a.id = b.id where b.fld = 1This only includes fields from the join where b.fld = 1 (i.e. is the same as an inner join as it excludes nulls)a left outer join b on a.id = b.id where (b.fld = 1 or b.fld is null)includes joined records where b.fld = 1 or those where no rec exists in b.Excludes recs from a where a join exists but all b recs have fld <> 1.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
manikandan
Starting Member
35 Posts |
Posted - 2002-09-03 : 09:22:50
|
| Hi nr,Thanks a lot. I just added the checking for is null in the where clause and it worked properly.And also i understood the concept.Thanks to SQL Team and nr.cheersmanikandanCheersManikandan |
 |
|
|
|
|
|
|
|