home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2945
Discussions: 188,378, Posts: 2,243,454, Members: 232,606
Old June 18th, 2008, 05:23 PM   Digg it!   #1 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,152
Help on running a specific SQL statement

So Im trying to figure out how to compare two tables and get a listing of records that do NOT appear in the other.

Table 1 contains information that Im comparing to Table 2 and I want any records in T1 that do NOT appear in T2 to show in the results. I have some examples below:

Code:
TABLE 1
T-Code		Auth_Object		Attribute	Attribute Value
-----------------------------------------------------------------------------
ME21		M_BEST_BSA		ACTVT		01
ME21		M_BEST_BSA		ACTVT		02
ME21		M_BEST_BSA		BSART		XX
ME21		M_BEST_EKG		ACTVT		01
ME21		M_BEST_EKG		EKGRP		XX

TABLE 2
T-Code		Auth_Object		Attribute	Attribute Value
-----------------------------------------------------------------------------
ME21		M_BEST_BSA		ACTVT		01
ME21		M_BEST_EKG		ACTVT		01
So when running the proposed query against the above data, I would want the following records to be included in the results:

Code:
T-Code		Auth_Object		Attribute	Attribute Value
-----------------------------------------------------------------------------
ME21		M_BEST_BSA		BSART		XX
ME21		M_BEST_BSA		ACTVT		02
ME21		M_BEST_EKG		EKGRP		XX
Any help in creating a query that will assist me in running this on a multitude of records in the tables? Thanks in advance.
__________________
YAH! I knew you'd be jealous

Tekk is online now   Reply With Quote
Old June 18th, 2008, 09:21 PM     #2 (permalink)
Super F@D Folder
 
Join Date: Jun 2004
Posts: 5,004
Send a message via AIM to sr71000

sr71000 is offline   Reply With Quote
Old June 18th, 2008, 09:48 PM     #3 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,017
Quote:
Originally Posted by sr71000 View Post
I would go with the join method in mentioned in this article

T-Code Auth_Object Attribute Attribute Value


select *
from table 1 t1
LEFT OUTER join table2 t2
on t1.[t-code] = t2.[t-code]
LEFT OUTER join table2 t2
on t1.[auth_object] = t2.[auth_object]
LEFT OUTER join table2 t2
on t1.[Attribute] = t2.[Attribute]
LEFT OUTER join table2 t2
on t1.[Attribute Value] = t2.[Attribute Value]
WHERE [t-code] IS NULL
OR [auth_object] IS NULL
OR Attribute IS NULL
OR [Attribute value] IS NULL

btw, this will give you half the results you want, you can figure out the rest


FYI I REALLY dont like the structure of this table

1. Spaces in column names
2. hyphens in column names
3. No standard in seperating words (I typically change case of first letter in each word AttributeValue). If you dont like changed case, then keep with underscore, with hyphens you have to use brackets and they're just annoying
4. Attribute and Attribute value probably shouldn't be in the same table.


Last edited by vass0922 : June 18th, 2008 at 09:51 PM.
vass0922 is online now   Reply With Quote
Old June 19th, 2008, 10:05 AM     #4 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,792
Send a message via AIM to Rootstonian
SELECT
A.T-CODE,
A.AUTH_OBJECT,
A.ATTRIBUTE,
A.ATTRIBUTE VALUE
FROM TABLE1 A
WHERE NOT EXISTS
(SELECT 'X'
FROM TABLE2 B
WHERE
A.T-CODE = B.T-CODE
AND A.AUTH_OBJECT = B.AUTH_OBJECT
AND A.ATTRIBUTE = B.ATTRIBUTE
AND A.ATTRIBUTE VALUE = B.ATTRIBUTE VALUE)
Rootstonian is online now   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
forming SQL Insert statement ShuckyD Webmastering and Programming 5 August 1st, 2007 08:49 AM
SQL statement help (pretty basic) ZeR0 Webmastering and Programming 2 February 23rd, 2006 01:38 PM
Running SQl server Scripts Sunayana Webmastering and Programming 2 October 25th, 2002 06:01 PM

Most Active Discussions
Is It Just Me? (2883)
The United States Debt (20)
Looks like Burris will get his Sena.. (8)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Titan quest and Immortal Throne, an.. (17)
Recent Discussions
New Build ( Finally ) (1)
dual monitors wont boot (0)
Folderchat Weekday thread (439)
MSN Hotmail Down??? (7)
Help with an Ati Radeon HD 4850.. (23)
Laptop waking up itself (0)
CPU wont boot (3)
Best digital camera for under 2.. (13)
Building first computer, will t.. (2)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:25 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28