Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 16th, 2004, 09:43 AM
cavall cavall is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 20 cavall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 26 sec
Reputation Power: 0
SQL statements not returning same values

I am trying to determin why one SQL statement using the CASE statement returns a set of values and the same statement not using the CASE statement in the select and placing its where condition directly in the WHERE clause returns no records... Any help in understanding why this is occurring would be greatly appreciated.... (SQL below)

This returns nothing:
SELECT labels.dt_tm_print,Count(lab_num) "LPN", labels.qty, labels.status,
labels.label_type, labels.line_num, labels.order_type,
labels.ord_num, labels.itm_num, labels.case_qty, labels.model_lot,
labels.hot_flg, labels.cust_num, labels.LOCATION, labels.dt_tm_void,
labels.dt_tm_recv, labels.dt_tm_shp, labels.reg_num,
labels.scan_type, labels.proc_type, labels.tran_num, labels.pic_zone,
labels.pick_wrk_asgn, labels.master_label, labels.dt_tm_divert,
labels.dt_tm_stage, labels.damage_flg, labels.vas_flg,
labels.audit_flg, labels.asn_num, labels.process_id,
labels.sell_zone, labels.carton_vol, labels.hbc_ovr_flg,
labels.reprint_date, labels.create_date, labels.act_reg_num,
labels.num_upc_prt
FROM labels
WHERE status<>45
AND lab_num like '98%'
AND dt_tm_print between to_date('09/11/04','MM/DD/YY') AND to_date('09/13/04','MM/DD/YY')
GROUP BY labels.dt_tm_print,
lab_num,
labels.qty,
labels.status,
labels.label_type,
labels.line_num,
labels.order_type,
labels.ord_num,
labels.itm_num,
labels.case_qty,
labels.model_lot,
labels.hot_flg,
labels.cust_num,
labels.LOCATION,
labels.dt_tm_void,
labels.dt_tm_recv,
labels.dt_tm_shp,
labels.reg_num,
labels.scan_type,
labels.proc_type,
labels.tran_num,
labels.pic_zone,
labels.pick_wrk_asgn,
labels.master_label,
labels.dt_tm_divert,
labels.dt_tm_stage,
labels.damage_flg,
labels.vas_flg,
labels.audit_flg,
labels.asn_num,
labels.process_id,
labels.sell_zone,
labels.carton_vol,
labels.hbc_ovr_flg,
labels.reprint_date,
labels.create_date,
labels.act_reg_num,
labels.num_upc_prt
ORDER BY labels.dt_tm_print DESC

This returns a ton of records but for the lab_num field (which is labeled "LPN" the value is blank:
SELECT labels.dt_tm_print,CASE WHEN lab_num like '98%' THEN lab_num END "LPN", labels.qty, labels.status,
labels.label_type, labels.line_num, labels.order_type,
labels.ord_num, labels.itm_num, labels.case_qty, labels.model_lot,
labels.hot_flg, labels.cust_num, labels.LOCATION, labels.dt_tm_void,
labels.dt_tm_recv, labels.dt_tm_shp, labels.reg_num,
labels.scan_type, labels.proc_type, labels.tran_num, labels.pic_zone,
labels.pick_wrk_asgn, labels.master_label, labels.dt_tm_divert,
labels.dt_tm_stage, labels.damage_flg, labels.vas_flg,
labels.audit_flg, labels.asn_num, labels.process_id,
labels.sell_zone, labels.carton_vol, labels.hbc_ovr_flg,
labels.reprint_date, labels.create_date, labels.act_reg_num,
labels.num_upc_prt
FROM labels
WHERE status<>45
AND dt_tm_print between to_date('09/11/04','MM/DD/YY') AND to_date('09/13/04','MM/DD/YY')
GROUP BY labels.dt_tm_print,
CASE WHEN lab_num like '98%' THEN lab_num END,
labels.qty,
labels.status,
labels.label_type,
labels.line_num,
labels.order_type,
labels.ord_num,
labels.itm_num,
labels.case_qty,
labels.model_lot,
labels.hot_flg,
labels.cust_num,
labels.LOCATION,
labels.dt_tm_void,
labels.dt_tm_recv,
labels.dt_tm_shp,
labels.reg_num,
labels.scan_type,
labels.proc_type,
labels.tran_num,
labels.pic_zone,
labels.pick_wrk_asgn,
labels.master_label,
labels.dt_tm_divert,
labels.dt_tm_stage,
labels.damage_flg,
labels.vas_flg,
labels.audit_flg,
labels.asn_num,
labels.process_id,
labels.sell_zone,
labels.carton_vol,
labels.hbc_ovr_flg,
labels.reprint_date,
labels.create_date,
labels.act_reg_num,
labels.num_upc_prt
ORDER BY labels.dt_tm_print DESC

Do I need to add the where lab_num like '98%' for all the other fileds also?

Thanks
cavall

Reply With Quote
  #2  
Old September 16th, 2004, 11:22 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
As you have accepted that the second query does not show any value in label because it does not comply the searching condition, and the same thing happened in your first query, returns no record, i dont know what is your table structure and what kinda data you have in it. so i just guess that label attribute is defined as character into the table and you have these two digits in your data set (i,e '98'), it might be anywhere whithin string (first, between, last). so your WHERE condition should be as follows:

modification is marked with red color,

AND lab_num like '%98%'

the other codition in your query is

WHERE status<>45

this might also be causing to generate no data, remove this condition and run your first query again without making any furthur modification, if you still found no data then use WHERE condition defined above (without WHERE status <>45).

Regards,

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > SQL statements not returning same values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway