Solved

how to use union and minus in Sybase ?

Posted on 2010-09-15
9
13,655 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
Industry Leaders: 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create table from select - oracle 6 67
Row_number in SQL 6 45
Oracle 12c Default Isolation Level 17 55
error doing substr 3 36
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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

756 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