Need help with complex SQL query (Sybase)


 
Thread Tools Search this Thread
Top Forums Programming Need help with complex SQL query (Sybase)
# 1  
Old 07-22-2008
Need help with complex SQL query (Sybase)

Hello,

I have three tables.

I need an SQL query (preferably Sybase) that will return all of the stringID values of table B where the following conditions exist:

(1) B.intID = A.intID
(2) B.intID != C.intID
or (B.intID = C.intID and
(C.v1 = 0 or C.v2 = 0))

Here are the table defs:

create table A (
intID int
}

create table B (
intID int,
stringID varchar(15)
)

create table C (
stringID varchar(15),
v1 int,
v2 int
)

Thanks for any input,
Elizabeth
# 2  
Old 07-22-2008
Correction to original post

(1) B.intID = A.intID
(2) B.stringID != C.stringID
or (B.stringID = C.stringID and
(C.v1 = 0 or C.v2 = 0))
# 3  
Old 07-23-2008
Not familiar with Sybase but you might want to try something like this.

Code:
 
SELECT B.stringID FROM A,B,C WHERE B.intID = A.intID AND ((B.stringID <> C.stringID) OR ((B.stringID = C.stringID) AND (C.v1 = 0 OR C.v2 = 0)));

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Sybase ASE - Query Tuning - Need Suggestion

Dear Team Please provide suggestion on below query which is used in Sybase Adaptive Server Enterprise/15.7 (ASE). Query takes more time > 30 Mins to 1 Hr All required indexes are built Can we have any efficient approach to get the data retrieval faster for below query.Any help... (0 Replies)
Discussion started by: Perlbaby
0 Replies

2. Programming

Sybase ASE: Query to find correct format issue.

Hi Team , I am new to Sybase Adaptive Server Enterprise/15.7 (ASE) and need some guidance to find the different values in serial format column. SELECT DISTINCT SERIAL_FORMAT FROM PRODUCTS It has values with below format which contains 12 digits hexadecimal characters with... (2 Replies)
Discussion started by: Perlbaby
2 Replies

3. Programming

Hierarchical Query for Sybase database

Team I am using DBartisan tool for sybase database. I have a table that has below fields Employee_ID,EMP_Name,First_Nm,Last_Nm,Emp_Designation,Employee's_Manager is it possible to retrieve hierarchical data based on below fields Emp_Designation will have Soft Engg,SSE,Team Lead,... (6 Replies)
Discussion started by: Perlbaby
6 Replies

4. Shell Programming and Scripting

Need to capture error of sybase sql in unix

Hi Gurus, I am very new in Unix, I have 1 script, in which I am truncating the table , then BCP the data in Sybase table, and then loading the data from sybase table to sybase table. every thing is working fine, but the problem is with Error. I made some hanges in my insert statement so... (1 Reply)
Discussion started by: aksar
1 Replies

5. Shell Programming and Scripting

Complex query

A file whose location i am not aware of contains the below text <url>jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(FAILOVER=on)(ADDRESS=(PROTOCOL=TCP) (HOST=ngm2sn1p2-vip.mybank.net)(PORT=4001))(ADDRESS=(PROTOCOL=TCP)(HOST=ngm2sn2p2-vip.mybank.net)... (1 Reply)
Discussion started by: mohtashims
1 Replies

6. Web Development

Complex MySQL Query(s)

Hi all, I have a bit of an issue, I am working on a bit of a CMDB for a friend, it's to do with real estate. Anyway, this is my situation. I have a table which contains all the properties (forsale, sold, etc) in the DB named "property". Now, this is what I want to achieve, I wish to... (5 Replies)
Discussion started by: STOIE
5 Replies

7. Shell Programming and Scripting

Bourne shell script with embedded Sybase SQL

Hi, I need a simple (as possible) Bourne shell script that takes an input file of adminID's and spits out a list of adminID's and related tradeID's. Both adminID and tradeID are columns in a Sybase database table called "trades", in which they have a one-to-one relationship. adminID is a... (3 Replies)
Discussion started by: chatieremerrill
3 Replies

8. UNIX for Advanced & Expert Users

Need sybase sql command help

Guys, My question is on the Sybase sql query, command 'sp_help' shows me list of all the tables. but I can not view them page by page. So is there any command to view them page by page as in our unix 'ls | less'. and one more thing command/procedure to store output into the file. Any... (4 Replies)
Discussion started by: jagdish.machhi@
4 Replies

9. Shell Programming and Scripting

Print out loop index on the console after executing each sybase DB query

Hello Guys, Well, using shell script, I'm doing loop on DB query as below: isql -Usa -Ptest -I /opt/sybase/interfaces << EOF use testdb go declare @i int select @i = 1 while(@i <= 5) begin Insert into TEST values (@i,"Test","TestDesc") select @i = @i + 1 end go EOF The Issue... (2 Replies)
Discussion started by: Alaeddin
2 Replies

10. Shell Programming and Scripting

Dynamic update loop query on Sybase database

Hello Guys, I'm new to Shell scripting, and i need someone to help me with this issue: I'm trying to do a dynamic update query on Sysbase database table using shell script. Lets say, the Update query is "update Table set id=X" , where X is dynamic value for the loop index. If the loop is... (10 Replies)
Discussion started by: Alaeddin
10 Replies
Login or Register to Ask a Question