If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Select statement - is there a limit in SQL language?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-04-04, 08:52
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Select statement - is there a limit in SQL language?

Hi,

I am interested if the following sample can be done in SQL statement.

Code:
Table: TAB

ID   OPERATOR     COL1    COL2
------------------------------------
1             <           100        90

And many many more records.
ID is primary key of table TAB.
I would like to compare COL2 value with COL1 according to the OPERATOR.
Someting like: SELECT CASE WHEN COL2 < COL1 THEN 'GOOD' ELSE 'BAD' END FROM TAB;

but instread of specifying '<' character I would like to get that operator from OPERATOR column.
Someting like: SELECT CASE WHEN COL2 OPERATOR COL1 THEN 'GOOD' ELSE 'BAD' END FROM TAB;

But above sql returs error:
SQL0104N An unexpected token "OPERATOR" was found following "SE WHEN
COL1". Expected tokens may include: "IN". SQLSTATE=42601

Is there any way to solve this problem in SQL? Can this be done in SQL?

Thanks,
Grofaty
Reply With Quote
  #2 (permalink)  
Old 03-04-04, 09:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
PHP Code:
select case when operator '<'
                    
and col2 col1 then 'good' 
            
when operator '<='
                    
and col2 <= col1 then 'good'  
            
when operator '='
                    
and col2 col1 then 'good'  
            
when operator '>'
                    
and col2 col1 then 'good'  
            
when operator '>='
                    
and col2 >= col1 then 'good'  
            
when operator '<>'
                    
and col2 <> col1 then 'good'  
            
else 'bad' end
  from tab 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-05-04, 01:08
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

Excellent!!! It works for me.

I have heard one SQL expert to say: "There is much greater change of limitation in knowledge then in SQL power".

Thank you very much,
Grofaty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On