Solved

how to use union and minus in Sybase ?

Posted on 2010-09-15
9
14,487 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
ClickHouse in a General Analytical Workload

We have mentioned ClickHouse in some recent posts, where it showed excellent results.

In this article on Experts Exchange, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

628 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