INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Union Query Gives Odd Results

Union Query Gives Odd Results

(OP)
I have the following code

CODE --> T-SQL

SELECT fldChecklistKey, fldOfficeKey, fldChecklistCode
FROM SourceDB.dbo.tblChecklist
WHERE fldOfficeKey = @OfficeKey
AND ISNULL(fldDeleteInd,0)= 0
UNION
SELECT fldChecklistKey, fldOfficeKey, fldChecklistCode
FROM TargetDB.dbo.tblCheckList
WHERE fldOfficeKey = @OfficeKey
AND ISNULL(fldDeleteInd,0) = 0
ORDER BY fldChecklistCode

SELECT *
FROM TargetDB.dbo.tblChecklist
WHERE fldChecklistCode = 'DHRC01AN' 

The result of running these two is (ignore hyphens - just used them to align the columns)

997A5356-1407-42FF-AFCC-EFB041DDC684 - 85DDE31C-E169-46A2-BF10-741EE1039E06 - CH01AN
23BE1EF9-80BE-4FB9-99F7-3C302ED258CB - 85DDE31C-E169-46A2-BF10-741EE1039E06 - DHRC01AN
10AA18D2-7C3C-423F-8090-76A97D6D9303 - 85DDE31C-E169-46A2-BF10-741EE1039E06 - DP01AN

23BE1EF9-80BE-4FB9-99F7-3C302ED258CB - E382085E-C1ED-46D3-9D2B-1B8B8BFD7541 - DHRC01AN

The problem is shown in the second query. @OfficeKey is equal to the 85DDE31C... value. However, as show by the simple second query, there is no Checklist Code DHRC01AN with an 85DDE31C... value in the TargetDB. It is known that only 85DDE31C... office keys exist in the SourceDB. How can I fix the union query so that only 85DDE31C... office keys result. The union query is giving 64 records, only 20 of which are from 85DDE31C... office.

RE: Union Query Gives Odd Results

So what do you get from...

CODE

SELECT fldChecklistKey, fldOfficeKey, fldChecklistCode
FROM TargetDB.dbo.tblCheckList
WHERE fldOfficeKey = 'DHRC01AN'
AND ISNULL(fldDeleteInd,0) = 0
ORDER BY fldChecklistCode

SELECT *
FROM TargetDB.dbo.tblChecklist
WHERE fldChecklistCode = 'DHRC01AN' 


Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Union Query Gives Odd Results

You have ORDER BY clause in your UNION query, so maybe
this:

23BE1EF9-80BE-4FB9-99F7-3C302ED258CB - 85DDE31C-E169-46A2-BF10-741EE1039E06 - DHRC01AN

is from SourceDB.dbo.tblChecklist

Borislav Borissov
VFP9 SP2, SQL Server

RE: Union Query Gives Odd Results

(OP)

Thank you both for your patience. I made two invalid assumptions. My instant first assumption was that there was something wrong with my UNION query, and second was that nothing had been added to the SourceDB after I loaded it. Indeed, all of the "extraneous" records are coming from the source db.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close