Solved

how to use union and minus in Sybase ?

Posted on 2010-09-15
9
13,940 Views
Last Modified: 2012-05-10
I have to compare 2 Sybase tables table_A and table_B , they have the same collum  name, they maybe have different data.
what i am thinking is :
select name, department,... from table_A
minus
select name,department,... from table_B

but Sybase does not support minus ?!

is there any similar SQL in Sybase?


0
Comment
Question by:SayYou_SayMe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 13

Accepted Solution

by:
alpmoon earned 300 total points
ID: 33688767
Do you have a key column? Is it ASE?

If name is primary key, I think this should work:

select * from table_A A
where not exists (select * from table_B B
                             where B.name = A.name)
0
 
LVL 6

Assisted Solution

by:sridharv9
sridharv9 earned 200 total points
ID: 33689025
As there is no minus operator available in ASE you can alternate option as above with "not exists" or "not in".
0
 

Author Comment

by:SayYou_SayMe
ID: 33690166
thanks guys

i have to compare all columns between tableA and tableB
just to compare the values in the tables if they are exactly the same
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Assisted Solution

by:sridharv9
sridharv9 earned 200 total points
ID: 33695175
Try this query to find any difference between two tables. Replace .d,.c,.b with table columns.

SELECT Table2.*
FROM Table2 LEFT JOIN Table1 ON (Table2.d = Table1.d) AND (Table2.c =
Table1.c) AND (Table2.b = Table1.b) AND (Table2.a = Table1.a) AND
(Table2.ID = Table1.ID)
WHERE (((Table1.ID) Is Null));
0
 

Author Comment

by:SayYou_SayMe
ID: 33696052
thanks guys

alpmoon--

your solution only works for checking one clumn Name, but i have to check all the fields are diferent .

another word, if the name is the same in both tables, it will show no result, whatever the other fields the same or not ( it do not match my request)

alpmoon--

your solution seems not work




0
 
LVL 13

Assisted Solution

by:alpmoon
alpmoon earned 300 total points
ID: 33698625
That was the reason I asked whether you have a primary key. If you need to compare all columns, you can add others in where clause:

select * from table_A A
where not exists (select * from table_B B
                             where B.name = A.name and B.department = A.department and ....)
0
 

Author Comment

by:SayYou_SayMe
ID: 33700602
thanks alpmoon

if there are more than 200 columns , is there any solution?
0
 
LVL 13

Assisted Solution

by:alpmoon
alpmoon earned 300 total points
ID: 33702591
Having a primary key or a better data model in general
0
 

Author Comment

by:SayYou_SayMe
ID: 33740220
I have 2 sybase tables
table_A
source, name, department,
New_York  Bill         IT
London        mike     HR
table_B
name,department
Bill   IT
Mike   HR

Table_B will have the data of New York or London

I want to create a stored procedure to compare the 2 tables if the values of columns are exactly the same and return a message


CREATE PROC data_chk
@source      VARCHAR(10)
as
begin
CREATE TABLE #t (source      VARCHAR(10)     null,
                   update_status            VARCHAR(100)    null)
select * from table_B a
where not exists (select * from table_A b
                  where isnull(a.name,' ')=isnull(b.name,' ')
                  and isnull(a.department,' ')=isnull(b.department,' ')
                  and a.source=@source)
if      @@rowcount = 0
  insert into #t
         values(@source,
                 'no update')
                 
                 
select      *
from      #t
return      0
end

I can run the stored procedure with no error, but I can not call it from Informatica, I will give error message
 --basically because it returna 2 result set
   One is :select * from table_B …
 One is select * from #T
But if  I  create the store procedure like this , it works
CREATE PROC data_chk
@source      VARCHAR(10)
as
begin
CREATE TABLE #t (source      VARCHAR(10)     null,
                   update_status            VARCHAR(100)    null)
/*select * from table_B a
where not exists (select * from table_A b
                  where isnull(a.name,' ')=isnull(b.name,' ')
                  and isnull(a.department,' ')=isnull(b.department,' ')
                  and a.source=@source)
if      @@rowcount = 0 */
  insert into #t
         values(@source,
                 'no update')
                 
                 
select      *
from      #t
return      0
end

question:
how to create this Sybase stored procedure to achieve my request?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Email query results in HTML 6 50
oracle differnce between two timestamps 5 53
SQL query for highest sequence 4 75
How do I search for a text string in my SQL code 18 52
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question