Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2006, 03:02 AM
Authorized User
 
Join Date: Sep 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to filter out unwanted data


I have the following fields in table A:

Date | Descrip | Amt Dr
----------------------------------
01/02/2006 | 740240 |(2,400.00)
14/02/2006 | 740241 |(3,000.00)
15/02/2006 | 41142 | 1,800.00
20/02/2006 | 41142 | 2,700.00
25/02/2006 | 740245 | 5,200.00

I have the following fields in table B:

Date | Descrip | Amt Dr
----------------------------------
02/02/2006 |88258 | 1,400.00
17/02/2006 |740244 | (1,500.00)
25/02/2006 |740245 | 5,200.00

There are no referencial key between TableA & TableB,
What i want is to extract the date,descrip & Amt data from
Table A where it's Descrip data is not the same as the data
in Table B's Descrip column.

My sql syntax is as follows:


SELECT
CASE WHEN TableA.Amt < 0 THEN TableA.[Date] ELSE 0 END,
CASE WHEN TableA.Amt < 0 THEN TableA.Descrip ELSE 0 END,
CASE WHEN TableA.Amt < 0 THEN TableA.Amt - (TableA.Amt * 2)ELSE 0 END AS [Add Back]
FROM TableA,TableB
WHERE TableA.Descrip <> TableB.Descrip
GROUP BY TableA.Date,TableA.Amt,TableA.Descrip

The output of the above is as follows:

Date | Descrip | Amt Dr
----------------------------------
01/02/2006 | 740240 |(2,400.00)
14/02/2006 | 740241 |(3,000.00)
15/02/2006 | 0 | 0
20/02/2006 | 0 | 0
25/02/2006 | 740245 | 5,200.00

Notice that, descrip with 740245 appearing in both tables
is what the sql should filter out, but failed to do so,
what i want is as below:


Date | Descrip | Amt Dr
----------------------------------
01/02/2006 | 740240 |(2,400.00)
14/02/2006 | 740241 |(3,000.00)


Can i achieve this? Please help.


 
Old April 25th, 2006, 10:44 AM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

fdtoo -- your requirements are not very clear, but I think this will give you what you want
SELECT
TableA.[Date] ,
TableA.Descrip,
 TableA.Amt [Add Back]
FROM TableA
LEFT JOIN TableB
ON TableA.Descrip = TableB.Descrip
WHERE TableB.Descrip IS NULL
AND TableA.Amt < 0
GROUP BY TableA.Date,TableA.Amt,TableA.Descrip


David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO Data Shape - Filter aggregate dwperry SQL Language 0 March 31st, 2008 10:40 AM
FUNCTION FILTER DATA FROM SQL DATABASE abofoma00 Javascript 1 November 21st, 2005 11:28 AM
how to filter out unwanted selection in rs paging gilgalbiblewheel Classic ASP Databases 1 October 18th, 2004 07:21 AM
How to filter data? coolest_pie SQL Server 2000 7 May 7th, 2004 07:00 PM
hide some unwanted data in report Subho Access VBA 6 December 12th, 2003 03:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.