Author |
Topic |
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-11-23 : 11:32:43
|
Could someone help me add this select statement...select clm from people where completedt is nullto the below query:SELECT n.DOC, ISNULL(COUNT(t.clmssn), 0) AS PendingInFOFROM t2DibPend AS t RIGHT OUTER JOINNatdocfile AS n ON n.DOC = t.doc AND DIB_MVT_SEQ_NUM IS NULLgroup by n.docorder by n.doc I'm using three tables...Here are the table definitions:CREATE TABLE [dbo].[T2DibPend]( [DOC] [varchar](3) NOT NULL, [CLM] [char](6) NOT NULL, [APP_RCPDT] [smalldatetime] NULL, [DIB_MVT_SEQ_NUM] [smallint] NULL, [ORG_ID] [varchar](4) NULL, [DIB_MVT_TYP] [char](1) NULL, [DIB_MVT_DT] [smalldatetime] NULL, [DIB_MVT_DEST] [varchar](4) NULL) ON [PRIMARY]insert into T2DibPendselect '674', '005746', '9/23/2010' ' ', ' ', ' ', ' ',' ' union allselect 'C65', '005747', '4/19/2010' '2', 'C54', 'T', '4/28/2010','S22' union allselect '002', '005760', '8/31/2010' '2', 'S22', 'R', '9/2/2010',' ' union allselect '240', '016461', '7/20/2010' '2', 'S14', 'R', '7/23/2010',' ' union allselect '200', '016461', '7/20/2010' '2', 'S14', 'R', '7/23/2010',' ' union allselect 'A38', '016561', '9/28/2010' ' ', ' ', ' ', ' ',' ' union allselect '022', '009544', '7/16/2010' '2', 'S51', 'R', '8/6/2010','' union allselect '045', '016569', '7/8/2010' '1', '045', 'T', '7/8/2010','S24' union allselect '034', '019580', '7/30/2010' '1', '034', 'T', '7/30/2010','S24' union allselect '055', '020703', '6/4/2010' '1', '055', 'T', '6/4/2010','V37' CREATE TABLE [dbo].[natdocfile]( [doc] [varchar](3) NOT NULL)insert into natdocfileselect '001' union allselect 'A00' union allselect '389' union allselect 'A38' union allselect '100' union allselect 'B14' union allselect '913' union allselect '009' union allselect '00K' union allselect '00N' union allselect '00U' CREATE TABLE [dbo].[people]( [clm] [char](6) NOT NULL, [lname] [char](6) NULL, [completedt] [datetime] NULL) Insert into peopleselect '001091', 'Wester', NULL union allselect '001142', 'Demare', '8/1/2008' union allselect '001091', 'Ricci', '6/15/2008' union allselect '001149', 'Chapma', '6/3/2010' union allselect '001096', 'Grogan', Null union allselect '009622', 'Powers', NULL union allselect '009621', 'Bonnel', '6/3/2010' union allselect '009622', 'Tallma', NULL |
|
X002548
Not Just a Number
15586 Posts |
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-11-23 : 13:19:54
|
Oops so sorry left out a comma try this:insert into T2DibPendselect '674', '005746', '9/23/2010', ' ', ' ', ' ', ' ',' ' union allselect 'C65', '005747', '4/19/2010', '2', 'C54', 'T', '4/28/2010','S22' union allselect '002', '005760', '8/31/2010', '2', 'S22', 'R', '9/2/2010',' ' union allselect '240', '016461', '7/20/2010', '2', 'S14', 'R', '7/23/2010',' ' union allselect '200', '016461', '7/20/2010', '2', 'S14', 'R', '7/23/2010',' ' union allselect 'A38', '016561', '9/28/2010', ' ', ' ', ' ', ' ',' ' union allselect '022', '009544', '7/16/2010', '2', 'S51', 'R', '8/6/2010','' union allselect '045', '016569', '7/8/2010', '1', '045', 'T', '7/8/2010','S24' union allselect '034', '019580', '7/30/2010', '1', '034', 'T', '7/30/2010','S24' union allselect '055', '020703', '6/4/2010', '1', '055', 'T', '6/4/2010','V37' |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-11-23 : 14:08:02
|
Okay sorry try this:SELECT n.DOC, ISNULL(COUNT(t.clm), 0) AS PendingInFOFROM t2DibPend AS t RIGHT OUTER JOINNatdocfile AS n ON n.DOC = t.doc AND DIB_MVT_SEQ_NUM IS NULLgroup by n.docorder by n.doc |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-11-23 : 14:33:33
|
I only took a bit of data to create the tables so I could get some help but it wasn't enough to give me the results that I want, it returns all 0's. So when I added the bold part and ran it against the t2DibPend table I have on my server I got results! I will check with the client to see if results are correct. SELECT n.DOC, ISNULL(COUNT(t.clm), 0) AS PendingInFO FROM t2DibPend AS t RIGHT OUTER JOINNatdocfile AS n ON n.DOC = t.doc AND DIB_MVT_SEQ_NUM IS NULL and t.clm not in (select clm from peoplewhere completedt is null)group by n.docorder by n.docIf you run the results from the sample data I sent I get:DOC PendingInFO001 0009 000K 000N 000U 0100 0389 0913 0A00 0A38 0B14 0 Thanks for your assistance. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-11-23 : 14:58:37
|
I have to include the cases in the People table that are null in my counts. The cases that have dates in the People table are called SDW cases. I don't want to inlcude those cases in my count.So I needed to add select clm from people where completedt is nullI hope this makes sense. |
|
|
|
|
|