473,379 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

how to use decode?case function in where clause

Hi I am using a select query from front end to generate report in such a way that I should be able to get records of Table W which are present in Table Y
The query which i am using is as follows:

Expand|Select|Wrap|Line Numbers
  1. Select Y.ntktno,Y.cpassengername,Y.cfromroute,Y.cuptoroute 
  2. from t_indi_infiledtl Y,t_indi_cancfiledtl W where Y.ntktno in 
  3. (select ntktno from t_indi_cancfiledtl) and Y.cfromroute=W.cfromroute and
  4. Y.cuptoroute=W.cuptoroute and 
  5. soundex(substr(Y.cpassengername,1,5))=soundex(substr(W.cpassengername,1,5)) 
By the above Query I am getting the desired output .
But I wants to check the minimum length of the passengername between (Y.cpassengername and W.cpassengername) and using that minimum length i wants to fire the query for the soundex function since i cant assume that soundex (Y.cpassengername)=soundex(W.cpassengername) for the first 5 characters Instead of 1st five characters I wants to take the minimum length
How can i solve the above problem.
Should i use Decode function or Case function and how in where clause????
Can anyone help me out of the above problem
Dec 21 '07 #1
2 13199
amitpatel66
2,367 Expert 2GB
Hi I am using a select query from front end to generate report in such a way that I should be able to get records of Table W which are present in Table Y
The query which i am using is as follows:

Expand|Select|Wrap|Line Numbers
  1. Select Y.ntktno,Y.cpassengername,Y.cfromroute,Y.cuptoroute 
  2. from t_indi_infiledtl Y,t_indi_cancfiledtl W where Y.ntktno in 
  3. (select ntktno from t_indi_cancfiledtl) and Y.cfromroute=W.cfromroute and
  4. Y.cuptoroute=W.cuptoroute and 
  5. soundex(substr(Y.cpassengername,1,5))=soundex(substr(W.cpassengername,1,5)) 
By the above Query I am getting the desired output .
But I wants to check the minimum length of the passengername between (Y.cpassengername and W.cpassengername) and using that minimum length i wants to fire the query for the soundex function since i cant assume that soundex (Y.cpassengername)=soundex(W.cpassengername) for the first 5 characters Instead of 1st five characters I wants to take the minimum length
How can i solve the above problem.
Should i use Decode function or Case function and how in where clause????
Can anyone help me out of the above problem
Do you mean you want to take the passengername of smaller length either from the table Y or table W. Then try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Select Y.ntktno,Y.cpassengername,Y.cfromroute,Y.cuptoroute 
  3. from t_indi_infiledtl Y,t_indi_cancfiledtl W where Y.ntktno in 
  4. (select ntktno from t_indi_cancfiledtl) and Y.cfromroute=W.cfromroute and
  5. Y.cuptoroute=W.cuptoroute and soundex(substr(Y.cpassengername,1,LEAST(LENGTH(Y.cpassengername),LENGTH(W.cpassengername))))=soundex(substr(W.cpassengername,1,LEAST(LENGTH(Y.cpassengername),LENGTH(W.cpassengername))))
  6.  
  7.  
Mar 3 '08 #2
Hi I am using a select query from front end to generate report in such a way that I should be able to get records of Table W which are present in Table Y
The query which i am using is as follows:

Expand|Select|Wrap|Line Numbers
  1. Select Y.ntktno,Y.cpassengername,Y.cfromroute,Y.cuptoroute 
  2. from t_indi_infiledtl Y,t_indi_cancfiledtl W where Y.ntktno in 
  3. (select ntktno from t_indi_cancfiledtl) and Y.cfromroute=W.cfromroute and
  4. Y.cuptoroute=W.cuptoroute and 
  5. soundex(substr(Y.cpassengername,1,5))=soundex(substr(W.cpassengername,1,5)) 
By the above Query I am getting the desired output .
But I wants to check the minimum length of the passengername between (Y.cpassengername and W.cpassengername) and using that minimum length i wants to fire the query for the soundex function since i cant assume that soundex (Y.cpassengername)=soundex(W.cpassengername) for the first 5 characters Instead of 1st five characters I wants to take the minimum length
How can i solve the above problem.
Should i use Decode function or Case function and how in where clause????
Can anyone help me out of the above problem



Expand|Select|Wrap|Line Numbers
  1.  
  2. select a.dly_ref_no,a.cns_no,a.cns_date,a.cnee_code,a.branch_branch_code,a.ranban
  3. where
  4. a.ac_year_code=b.ac_year_code and
  5. a.branch_branch_code=b.branch_branch_code and
  6. a.branch_branch_code=decode('column_value','ALL',a.branch_branch_code,'column_value') and
  7. group by a.dly_ref_no,a.cns_no,a.cns_date,a.cnee_code,a.branch_branch_code,a.ranban
  8.  
  9.  
Mar 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sherman H. | last post by:
I have to run a query to give a column a value based on a time range. Can I use DECODE? select decode(trans_date, trans_date>='01-Jul-2002' and trans_date<='30-Jun-2003','Fiscal2002', .....) as...
3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By Clause but unable to use it in WHERE CLAUSE. PLS...
10
by: N | last post by:
What is the function in SQL that works like DECODE in Oracle?" Thanks, N
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
2
by: Amin Schoeib | last post by:
Hi, Like I see there is no equivalent to the Oracle decode Function In Postgres.Is there maybe somebody who wrote decode as a Function? Schoeib 4Tek Gesellschaft für angewandte...
1
by: MP | last post by:
I have the following command. SELECT A.STORE_NAME, A.STORE_NUM, A.ZIP_CODE, B.EMPLOYEE_ID, B.GENDER, B.EMP_LEVEL, C.ITEM_CODE, DECODE(B.ITEM_CODE,1, 'CHICK_BURGERS') ITEM_DESCR,...
7
by: mandible | last post by:
Hello I'm trying to have some control on how my data is ordered depending on an input parameter my question is in a stored procedure how can I do something like this at the end of my...
16
by: Medhatithi | last post by:
Hi, I am facing a strange problem with decode function in oracle. My table name is status_hist. Below is the query I am hitting on this table: select...
5
by: Sascha.Moellering | last post by:
Hi, I receive the error code SQL0338N if I try to compile this statement (part of the statement): .... left outer join lateral (SELECT * FROM LIZSYSABA.VWZL0359TBS WHERE tbs_name = CASE WHEN...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.