Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mikebird
Aged Yak Warrior
529 Posts |
Posted - 2009-06-23 : 08:05:09
|
| What's wrong?where I say:and centre_no = 'DV066'why do I get 72,008 rows?The row IS there. Why can't I eliminate the rest? The most basic filter. The 0 is a 0. A zero. Is it the joins?select distinctcentre_no,centre_name,det_year,det_quantity,det_type,det_unit_price det_money,prcode,stkcode,stk_baseprice Stock_money,pr_price Price_money,pr_sort_key Price_Category,stk_sort_key Stock_Category,pr_usrchar1 Price_net,stk_sort_key3 Stock_net,st_nett,nl_cat_code4,nl_categorynamefromfinancetemplate.dbo.sl_pl_nl_detail detleft join financetemplate.dbo.stk_stock s on stkcode = det.det_stock_codeleft join financetemplate.dbo.prc_price_recs p on prcode = det.det_price_codeinner join financetemplate.dbo.sl_accounts sla on sla.cucode = det.det_accountinner join asdandat.dbo.tbl_centre c on c.centre_no = sla.cucodeinner join financetemplate.dbo.sl_transactions t on det.det_header_ref = t.st_header_refinner join financetemplate.dbo.nl_category nlc on right(det.det_analysis, 3) = nlc.nl_cat_code4left join financetemplate.dbo.prc_price_recs2 p2 on p2.prcode2 = p.prcodewhere c.reg_status = 'R' and centre_no = 'DV066'and det_year = 'L'and prcode = 'ASWB01'and det_quantity > 5and pr_sort_key in ('REGISTRATIONS', 'CANDIDATE FEES') or stk_sort_key in ('STUDENT BOOKS', 'RESOURCE BOOKLETS')and pr_sort_key is not null or stk_sort_key is not nullorder by centre_no, pr_sort_key, stk_sort_key |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-06-23 : 08:22:22
|
| the OR conditions in your WHERE clause is causing this, you need to put proper paranthesis around them. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-23 : 08:22:31
|
try thisselect distinctcentre_no,centre_name,det_year,det_quantity,det_type,det_unit_price det_money,prcode,stkcode,stk_baseprice Stock_money,pr_price Price_money,pr_sort_key Price_Category,stk_sort_key Stock_Category,pr_usrchar1 Price_net,stk_sort_key3 Stock_net,st_nett,nl_cat_code4,nl_categorynamefromasdandat.dbo.tbl_centre c inner join financetemplate.dbo.sl_accounts sla on sla.cucode = c.centre_noinner join financetemplate.dbo.sl_pl_nl_detail det on sla.cucode = det.det_accountleft join financetemplate.dbo.stk_stock s on stkcode = det.det_stock_codeleft join financetemplate.dbo.prc_price_recs p on prcode = det.det_price_code and p.prcode = 'ASWB01'inner join financetemplate.dbo.sl_transactions t on det.det_header_ref = t.st_header_refinner join financetemplate.dbo.nl_category nlc on right(det.det_analysis, 3) = nlc.nl_cat_code4left join financetemplate.dbo.prc_price_recs2 p2 on p2.prcode2 = p.prcodewhere c.reg_status = 'R'and centre_no = 'DV066'and det_year = 'L'and det_quantity > 5and (pr_sort_key in ('REGISTRATIONS', 'CANDIDATE FEES') or stk_sort_key in ('STUDENT BOOKS', 'RESOURCE BOOKLETS'))order by centre_no, pr_sort_key, stk_sort_key |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-23 : 08:41:52
|
This doesn't seem right.Only last three characters for a column named Code4?inner join financetemplate.dbo.nl_category nlc on right(det.det_analysis, 3) = nlc.nl_cat_code4inner join financetemplate.dbo.nl_category nlc on right(det.det_analysis, 4) = nlc.nl_cat_code4 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|
|
|