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 |
sherrireid
Yak Posting Veteran
58 Posts |
Posted - 2013-07-25 : 15:29:34
|
Hi:I have a query that is looking at invoices that are discrepant. It requires that I count the discrepant info by discrepant code and in an SSRS report display the code and the discrepant number. Then clicking on a code would show the detail of the invoices that are discrepant.The problem is that when I count the discrepant codes it comes up with 11 for example, but when I look at the data there are 13 rows of data.Does anyone have an idea on why I might have my counts off?Here is my sql:create table #DISCRInfo (DISCRCount int,DISCRCode varchar(20))insert into #DISCRInfo(DISCRCount, DISCRCode)select distinctCOUNT(INV_LINE_DISCR.INV_LINE_DISCR_ID),INV_LINE_DISCR.INV_DISCR_CDfrom INV_LINE_DISCRwhere INV_LINE_DISCR.REVIEW_DATE >= '07/01/2013' andINV_LINE_DISCR.REVIEW_DATE <= '07/05/2013' andINV_DISCR_RES_CD is not nullgroup by INV_LINE_DISCR.INV_DISCR_CDorder by INV_LINE_DISCR.INV_DISCR_CDSELECT DISTINCT CAST (#DISCRInfo.DISCRCount AS VARCHAR(10)) + '-' + INV_LINE_DISCR.INV_DISCR_CD AS DISCR_CODE,CODE_TABLE.NAME AS CODE_DESCR,min(INV_LINE_DISCR.REVIEW_DATE)AS DiscrepancyDate,max(INV_LINE_DISCR.REVIEW_DATE)AS ResolveDate,USR.NAME AS AP_TECH,SUB_ACCT.NAME as BUDGET,MFR.NAME AS SUPPLIER,INV.PO_NO,INV.INV_NOFROM INVJOIN INV_LINE ON INV.INV_ID = INV_LINE.INV_IDJOIN INV_LINE_DISCR ON INV_LINE_DISCR.INV_LINE_ID = INV_LINE.INV_LINE_IDJOIN POon INV.PO_NO = PO.PO_NOJOIN USRon USR.USR_ID = INV.APPR_USR_IDJOIN CODE_TABLEon CODE_TABLE.TYPE_CD = INV_LINE_DISCR.INV_DISCR_CDJOIN SUB_ACCTon SUB_ACCT.SUB_ACCT_ID = INV_LINE.SUB_ACCT_IDThanks for any suggestions.SLReidForum NewbieRenton, WA USA |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-07-25 : 23:22:10
|
Do you have duplicate discrepant codes in you output? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-26 : 00:06:01
|
you've a series of joins. Are you suer you'll have matching entries in all the tabled for those 13 records? JOIN will filter out unmatched entries which might be why you're missing two. Another possibility is availability of duplicates as per earlier suggestion------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|