Example with 2 unique qualifiers |
Top Previous Next |
Example from Oregon DOT. In this example each street's uniqueness is dependent on both a Cnty_Id and City_Sect value. Note though, that in this particular case, the source data does not include Cnty_id and City_Sect_id for the streets, just for the crash. As a result, it is not possible to identify all crashes at intersections on county or city boundaries unless the crashes are coded consistently to a single agency. Also, this example sorts by county, city, street and cross street. This is not required, but makes examination of data query results easier.
SELECT Crash.Cnty_Id AS Cnty_Id, Crash.City_Sect_Id AS City_Sect_Id, S1.StreetName AS St_Full_Nm, S2.StreetName AS Isect_St_Full_Nm
FROM ( dbo.CRASH Crash LEFT JOIN dbo.Streets S1 ON ((S1.StreetNum=Crash.St_Full_Id) AND (S1.CNTY_ID=Crash.Cnty_Id) AND (S1.CITY_SECT_ID=Crash.City_Sect_Id))) LEFT JOIN dbo.Streets S2 ON ((S2.StreetNum=Crash.ISect_St_Full_Id) AND (S2.CNTY_ID=Crash.Cnty_Id) AND (S2.CITY_SECT_ID=Crash.City_Sect_Id))
UNION
SELECT Crash.Cnty_Id AS Cnty_Id, Crash.City_Sect_Id AS City_Sect_Id, S1.StreetName AS St_Full_Nm, S2.StreetName AS Isect_St_Full_Nm
FROM ( dbo.CRASH Crash LEFT JOIN dbo.Streets S1 ON ((S1.StreetNum=Crash.ISect_St_Full_Id) AND (S1.CNTY_ID=Crash.Cnty_Id) AND (S1.CITY_SECT_ID=Crash.City_Sect_Id))) LEFT JOIN dbo.Streets S2 ON ((S2.StreetNum=Crash.St_Full_Id) AND (S2.CNTY_ID=Crash.Cnty_Id) AND (S2.CITY_SECT_ID=Crash.City_Sect_Id))
ORDER BY Cnty_Id, City_Sect_id, St_Full_Nm, ISect_St_Full_Nm
Raw XML. The second (copied) query definition is highlighted in blue. The changed union type and streets are highlighted in yellow as they are above.
<pdroot> <Settings/> <QueryDefinition> <ExprQualifier>C</ExprQualifier> <UnionType/> <ConnectionName>Reader</ConnectionName> <LinkageList> <Linkage> <Table>dbo.CRASH</Table> <Alias>Crash</Alias> <JoinType>INNER</JoinType> <DefaultFieldSuffix/> <FieldList> <Field> <Name>Cnty_Id</Name> <Alias>Cnty_Id</Alias> <LookupKey>CNTY_ID</LookupKey> <MimeType>text/plain</MimeType> <Enabled>True</Enabled> <NormalizedField>None</NormalizedField> <DataType>FixedChar</DataType> </Field> <Field> <Name>City_Sect_Id</Name> <Alias>City_Sect_Id</Alias> <LookupKey>CITY_SECT_ID</LookupKey> <MimeType>text/plain</MimeType> <Enabled>True</Enabled> <NormalizedField>None</NormalizedField> <DataType>Integer</DataType> </Field> </FieldList> <JoinPairList/> </Linkage> <Linkage> <Table>dbo.Streets</Table> <Alias>S1</Alias> <JoinType>LEFT OUTER</JoinType> <DefaultFieldSuffix/> <FieldList> <Field> <Name>StreetName</Name> <Alias>St_Full_Nm</Alias> <LookupKey>None</LookupKey> <MimeType>text/plain</MimeType> <Enabled>True</Enabled> <NormalizedField>None</NormalizedField> <DataType>WideString</DataType> </Field> </FieldList> <JoinPairList> <JoinPair> <Field>StreetNum</Field> <Value>Crash.St_Full_Id</Value> </JoinPair> <JoinPair> <Field>CNTY_ID</Field> <Value>Crash.Cnty_Id</Value> </JoinPair> <JoinPair> <Field>CITY_SECT_ID</Field> <Value>Crash.City_Sect_Id</Value> </JoinPair> </JoinPairList> </Linkage> <Linkage> <Table>dbo.Streets</Table> <Alias>S2</Alias> <JoinType>LEFT OUTER</JoinType> <DefaultFieldSuffix/> <FieldList> <Field> <Name>StreetName</Name> <Alias>Isect_St_Full_Nm</Alias> <LookupKey>None</LookupKey> <MimeType>text/plain</MimeType> <Enabled>True</Enabled> <NormalizedField>None</NormalizedField> <DataType>WideString</DataType> </Field> </FieldList> <JoinPairList> <JoinPair> <Field>StreetNum</Field> <Value>Crash.ISect_St_Full_Id</Value> </JoinPair> <JoinPair> <Field>CNTY_ID</Field> <Value>Crash.Cnty_Id</Value> </JoinPair> <JoinPair> <Field>CITY_SECT_ID</Field> <Value>Crash.City_Sect_Id</Value> </JoinPair> </JoinPairList> </Linkage> </LinkageList> <WhereClauseList> </WhereClauseList> <OrderByList> <OrderBy> <Field>Cnty_Id</Field> <AscDesc>Asc</AscDesc> </OrderBy> <OrderBy> <Field>City_Sect_Id</Field> <AscDesc>Asc</AscDesc> </OrderBy> <OrderBy> <Field>St_Full_Nm</Field> <AscDesc>Asc</AscDesc> </OrderBy> <OrderBy> <Field>Isect_St_Full_Nm</Field> <AscDesc>Asc</AscDesc> </OrderBy> </OrderByList> <UnionQueries> <QueryDefinition> <ExprQualifier>C</ExprQualifier> <UnionType>UNION</UnionType> <ConnectionName>Reader</ConnectionName> <LinkageList> <Linkage> <Table>dbo.CRASH</Table> <Alias>Crash</Alias> <JoinType>INNER</JoinType> <DefaultFieldSuffix/> <FieldList> <Field> <Name>Cnty_Id</Name> <Alias>Cnty_Id</Alias> <LookupKey>CNTY_ID</LookupKey> <MimeType>text/plain</MimeType> <Enabled>True</Enabled> <NormalizedField>None</NormalizedField> <DataType>FixedChar</DataType> </Field> <Field> <Name>City_Sect_Id</Name> <Alias>City_Sect_Id</Alias> <LookupKey>CITY_SECT_ID</LookupKey> <MimeType>text/plain</MimeType> <Enabled>True</Enabled> <NormalizedField>None</NormalizedField> <DataType>Integer</DataType> </Field> </FieldList> <JoinPairList/> </Linkage> <Linkage> <Table>dbo.Streets</Table> <Alias>S1</Alias> <JoinType>LEFT OUTER</JoinType> <DefaultFieldSuffix/> <FieldList> <Field> <Name>StreetName</Name> <Alias>St_Full_Nm</Alias> <LookupKey>None</LookupKey> <MimeType>text/plain</MimeType> <Enabled>True</Enabled> <NormalizedField>None</NormalizedField> <DataType>WideString</DataType> </Field> </FieldList> <JoinPairList> <JoinPair> <Field>StreetNum</Field> <Value>Crash.ISect_St_Full_Id</Value> </JoinPair> <JoinPair> <Field>CNTY_ID</Field> <Value>Crash.Cnty_Id</Value> </JoinPair> <JoinPair> <Field>CITY_SECT_ID</Field> <Value>Crash.City_Sect_Id</Value> </JoinPair> </JoinPairList> </Linkage> <Linkage> <Table>dbo.Streets</Table> <Alias>S2</Alias> <JoinType>LEFT OUTER</JoinType> <DefaultFieldSuffix/> <FieldList> <Field> <Name>StreetName</Name> <Alias>Isect_St_Full_Nm</Alias> <LookupKey>None</LookupKey> <MimeType>text/plain</MimeType> <Enabled>True</Enabled> <NormalizedField>None</NormalizedField> <DataType>WideString</DataType> </Field> </FieldList> <JoinPairList> <JoinPair> <Field>StreetNum</Field> <Value>Crash.St_Full_Id</Value> </JoinPair> <JoinPair> <Field>CNTY_ID</Field> <Value>Crash.Cnty_Id</Value> </JoinPair> <JoinPair> <Field>CITY_SECT_ID</Field> <Value>Crash.City_Sect_Id</Value> </JoinPair> </JoinPairList> </Linkage> </LinkageList> <WhereClauseList> </WhereClauseList> <OrderByList> <OrderBy> <Field>S1.StreetName</Field> <AscDesc>Asc</AscDesc> </OrderBy> <OrderBy> <Field>S1.Cnty_Id</Field> <AscDesc>Asc</AscDesc> </OrderBy> <OrderBy> <Field>S1.City_Sect_Id</Field> <AscDesc>Asc</AscDesc> </OrderBy> <OrderBy> <Field>S2.StreetName</Field> <AscDesc>Asc</AscDesc> </OrderBy> <OrderBy> <Field>S2.Cnty_Id</Field> <AscDesc>Asc</AscDesc> </OrderBy> <OrderBy> <Field>S2.City_Sect_Id</Field> <AscDesc>Asc</AscDesc> </OrderBy> </OrderByList> <UnionQueries> </UnionQueries> </QueryDefinition> </UnionQueries> </QueryDefinition> <CalculatedFields/> </pdroot>
|