Invalid column names ERROR - sql

i have a simple query below. but I don't know why I am getting an invalid column names error for field names and error value in where clause.
select * From (
select [SubscriberDataId]
,Case When ISNUMERIC([SubscriberCode]) = 0 Then cast([SubscriberCode]as varchar(9)) Else '~' end as [SubscriberCode]
,Case When ISDATE([Dob]) = 0 Then Cast([Dob] as Varchar(9)) Else '~' end as [Dob]
,Case When ISNUMERIC([FacetsGroup]) = 0 Then cast([FacetsGroup]as varchar(9)) Else '~' end as [FacetsGroup]
from Facets.SubscriberData) [sd]
Unpivot
(ErrorValue for FieldName in ([SubscriberCode],
[Dob],[FacetsGroup])) as x
where x.ErrorValue <> '~' and
NOT EXISTS (SELECT *
FROM Elig.dbo.ErrorTable
WHERE TableName = facets.SubscriberData
AND FieldName IN( [x].[SubscriberCode],[x].[Dob],[x].[FacetsGroup])
AND ErrorValue IN( [SubscriberCode],[Dob],[FacetsGroup]))

try
select * From
(select [SubscriberDataId],
Case When ISNUMERIC([SubscriberCode]) = 0
Then cast([SubscriberCode]as varchar(9))
Else '~' end as [SubscriberCode],
Case When ISDATE([Dob]) = 0
Then Cast([Dob] as Varchar(9))
Else '~' end as [Dob],
Case When ISNUMERIC([FacetsGroup]) = 0
Then cast([FacetsGroup]as varchar(9))
Else '~' end as [FacetsGroup]
from Facets.SubscriberData) [sd]
Unpivot (ErrorValue for FieldName in ([SubscriberCode], [Dob],[FacetsGroup])) as x where x.ErrorValue <> '~'
and NOT EXISTS (SELECT * FROM Elig.dbo.ErrorTable
WHERE TableName = facets.SubscriberData
AND FieldName IN( '[x].[SubscriberCode]','[x].[Dob]','[x].[FacetsGroup]')
AND ErrorValue IN( '[SubscriberCode]','[Dob]','[FacetsGroup]'))

Related

CREATE VIEW IN DB2

I have a DB2 SQL statement which selects the required rows successfully. Since its a time consuming query, I am trying to convert it into a view using the create view statement.
WITH firstequiprrn
AS (SELECT oeord# equiporder,
Min(RRN(a)) firstrow
FROM iesqafile.OPEQUIP a
GROUP BY oeord#
ORDER BY 1),
firstequiprow
AS (SELECT oeord#,
oetrlr equipmentnumber
FROM firstequiprrn
INNER JOIN iesqafile.OPEQUIP b
ON equiporder = oeord#
AND firstrow = RRN(b)),
ordermiles
AS (SELECT mmord#,
mmtotal
FROM iesqafile.mmiles
WHERE mmord# IN(SELECT orodr#
FROM iesqafile.order)
AND mmrectype = 'O'
AND mmdsp# = '00'),
stopgroup
AS (SELECT soord stoporder,
COUNT(*) stopsremain,
Min(sostp#) nextstop,
Max(soappr) apptreq,
Max(soaptm) apptmade
FROM iesqafile.stopoff
INNER JOIN iesqafile.order
ON orodr# = soord
WHERE soardt = 0
GROUP BY soord
ORDER BY 1) SELECT a.orodr# orodr_,
orcust,
orldat,
CASE orpdat
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orpdat), 'YYYY-MM-DD')
END erdat2,
CASE orptim
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(orptim, 1, 2), ':'),
SUBSTRING(orptim, 3, 4))
END AS ertim2,
CASE orapdt
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orapdt), 'YYYY-MM-DD')
END ltdat2,
CASE oraptm
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(oraptm, 1, 2), ':'),
SUBSTRING(oraptm, 3, 4))
END AS lttim2,
CASE orddat
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orddat), 'YYYY-MM-DD')
END dldat2,
CASE ordtim
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(ordtim, 1, 2), ':'),
SUBSTRING(ordtim, 3, 4))
END AS dltim2,
orestr,
a.ordv# ordv_,
orcons,
oreqty,
orspec,
a.orstp# orstp_,
orcomc,
( CASE
WHEN mmtotal IS NOT NULL THEN mmtotal
ELSE 0
END ) mmtotal,
orwgt,
orocty,
orost,
ordcty,
ordst,
orara asarea,
orpdrv oprdrv,
orld# orld_,
ordsp# ordsp_,
orshdt,
orshtm,
ornwpk,
( CASE
WHEN equipmentnumber IS NOT NULL THEN equipmentnumber
ELSE ''
END ) EquipmentNumber,
( CASE
WHEN apptreq IS NOT NULL THEN apptreq
ELSE 'N'
END ) apptreq,
( CASE
WHEN apptmade IS NOT NULL THEN apptmade
ELSE 'N'
END ) apptmade,
( CASE
WHEN ununit IS NOT NULL THEN ununit
ELSE ' '
END ) UNUNIT,
( CASE
WHEN unsupr IS NOT NULL THEN unsupr
ELSE ' '
END ) asdrmgr,
( CASE
WHEN unfmgr IS NOT NULL THEN unfmgr
ELSE ' '
END ) asflmgr,
( CASE
WHEN untrl1 IS NOT NULL THEN untrl1
ELSE ' '
END ) UNTRL1
FROM iesqafile.order a
LEFT OUTER JOIN ordermiles
ON mmord# = a.orodr#
LEFT OUTER JOIN firstequiprow
ON a.orodr# = oeord#
LEFT OUTER JOIN stopgroup
ON a.orodr# = stoporder
LEFT OUTER JOIN iesqafile.units
ON ununit = a.orpdrv
WHERE orld# <> ordsp#
AND ( orspec = 'N# C'
OR orspec = 'N# P' )
AND orpdrv <> ''
AND orpdat >= 2018001
UNION
SELECT d.orodr# as ordddd,
orcust,
orldat,
CASE orpdat
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orpdat), 'YYYY-MM-DD')
END erdat2,
CASE orptim
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(orptim, 1, 2), ':'),
SUBSTRING(orptim, 3, 4))
END AS ertim2,
CASE orapdt
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orapdt), 'YYYY-MM-DD')
END ltdat2,
CASE oraptm
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(oraptm, 1, 2), ':'),
SUBSTRING(oraptm, 3, 4))
END AS lttim2,
CASE orddat
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orddat), 'YYYY-MM-DD')
END dldat2,
CASE ordtim
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(ordtim, 1, 2), ':'),
SUBSTRING(ordtim, 3, 4))
END AS dltim2,
orestr,
ordv#,
orcons,
oreqty,
orspec,
orstp#,
orcomc,
( CASE
WHEN mmtotal IS NOT NULL THEN mmtotal
ELSE 0
END ) mmtotal,
orwgt,
orocty,
orost,
ordcty,
ordst,
orara,
orpdrv,
orld#,
ordsp#,
orshdt,
orshtm,
ornwpk,
( CASE
WHEN equipmentnumber IS NOT NULL THEN equipmentnumber
ELSE ' '
END ) EquipmentNumber,
( CASE
WHEN apptreq IS NOT NULL THEN apptreq
ELSE 'N'
END ) apptreq,
( CASE
WHEN apptmade IS NOT NULL THEN apptmade
ELSE 'N'
END ) apptmade,
( CASE
WHEN ununit IS NOT NULL THEN ununit
ELSE ' '
END ) UNUNIT,
( CASE
WHEN unsupr IS NOT NULL THEN unsupr
ELSE ' '
END ) UNSUPR,
( CASE
WHEN unfmgr IS NOT NULL THEN unfmgr
ELSE ' '
END ) UNFMGR,
( CASE
WHEN untrl1 IS NOT NULL THEN untrl1
ELSE ' '
END ) UNTRL1
FROM iesqafile.opplan
LEFT OUTER JOIN iesqafile.order d
ON d.orodr# = opord#
LEFT OUTER JOIN ordermiles
ON mmord# = d.orodr#
LEFT OUTER JOIN firstequiprow
ON d.orodr# = oeord#
LEFT OUTER JOIN stopgroup
ON d.orodr# = stoporder
LEFT OUTER JOIN iesqafile.units
ON ununit = d.orpdrv
So my first attempt to create the view was simply to add a CREATE VIEW AS at the beginning of the first statement. This resulted in the error below:
A column list must be specified because the result columns are unnamed.
I am failing to understand this error as the column headings are indeed specified as the select works without issues. All columns are displayed with appropriate headings.
However I tried to modify the query by adding the below instead of the simple create view.
create view pavt.v1 (v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25,v26,v27,v28,v29,v30,v31,v32,v33,v34,v35,v36) as
This seemed to have worked and the view was created in library PAVT. However when I run a select on the view, I get an aritmetic overflow error with DB2 error code of -802.
I dont understand this as I am able to view the results but the issue comes only while attempting to create the query. Can somebody guide please?
A more detailed error description is below:
Message . . . . : Select or omit error on field
Cast(Translate(ORDER_14.ORPTIM, *UNNAMED Table) AS member V.
Cause . . . . . : A select or omit error occurred in record 0, record format
*FIRST, member number 1 of file V in library PAVT, because of condition 1 of
the following conditions:
1 - The data was not valid in a decimal field.
At this moment what I really want to know is if the method I am following to create the view is correct (atleast as far as the syntax goes). Maybe the error I am seeing is a data error?
Edit-1:
create view pavt.CCC1 as
WITH firstequiprrn
AS (SELECT oeord# equiporder,
Min(RRN(a)) firstrow
FROM iesqafile.OPEQUIP a
GROUP BY oeord#
ORDER BY 1),
firstequiprow
AS (SELECT oeord#,
oetrlr equipmentnumber
FROM firstequiprrn
INNER JOIN iesqafile.OPEQUIP b
ON equiporder = oeord#
AND firstrow = RRN(b)),
ordermiles
AS (SELECT mmord#,
mmtotal
FROM iesqafile.mmiles
WHERE mmord# IN(SELECT orodr#
FROM iesqafile.order)
AND mmrectype = 'O'
AND mmdsp# = '00'),
stopgroup
AS (SELECT soord stoporder,
COUNT(*) stopsremain,
Min(sostp#) nextstop,
Max(soappr) apptreq,
Max(soaptm) apptmade
FROM iesqafile.stopoff
INNER JOIN iesqafile.order
ON orodr# = soord
WHERE soardt = 0
GROUP BY soord
ORDER BY 1) SELECT a.orodr# orodr_,
orcust,
orldat,
CASE orpdat
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orpdat), 'YYYY-MM-DD')
END erdat2,
CASE orptim
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(char(orptim), 1, 2), ':'),
SUBSTRING(char(orptim), 3, 4))
END AS ertim2,
CASE orapdt
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orapdt), 'YYYY-MM-DD')
END ltdat2,
CASE oraptm
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(oraptm, 1, 2), ':'),
SUBSTRING(oraptm, 3, 4))
END AS lttim2,
CASE orddat
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orddat), 'YYYY-MM-DD')
END dldat2,
CASE ordtim
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(ordtim, 1, 2), ':'),
SUBSTRING(ordtim, 3, 4))
END AS dltim2,
orestr,
a.ordv# ordv_,
orcons,
oreqty,
orspec,
a.orstp# orstp_,
orcomc,
( CASE
WHEN mmtotal IS NOT NULL THEN mmtotal
ELSE 0
END ) mmtotal,
orwgt,
orocty,
orost,
ordcty,
ordst,
orara asarea,
orpdrv oprdrv,
orld# orld_,
ordsp# ordsp_,
orshdt,
orshtm,
ornwpk,
( CASE
WHEN equipmentnumber IS NOT NULL THEN equipmentnumber
ELSE ''
END ) EquipmentNumber,
( CASE
WHEN apptreq IS NOT NULL THEN apptreq
ELSE 'N'
END ) apptreq,
( CASE
WHEN apptmade IS NOT NULL THEN apptmade
ELSE 'N'
END ) apptmade,
( CASE
WHEN ununit IS NOT NULL THEN ununit
ELSE ' '
END ) UNUNIT,
( CASE
WHEN unsupr IS NOT NULL THEN unsupr
ELSE ' '
END ) asdrmgr,
( CASE
WHEN unfmgr IS NOT NULL THEN unfmgr
ELSE ' '
END ) asflmgr,
( CASE
WHEN untrl1 IS NOT NULL THEN untrl1
ELSE ' '
END ) UNTRL1
FROM iesqafile.order a
LEFT OUTER JOIN ordermiles
ON mmord# = a.orodr#
LEFT OUTER JOIN firstequiprow
ON a.orodr# = oeord#
LEFT OUTER JOIN stopgroup
ON a.orodr# = stoporder
LEFT OUTER JOIN iesqafile.units
ON ununit = a.orpdrv
WHERE orld# <> ordsp#
AND ( orspec = 'N# C'
OR orspec = 'N# P' )
AND orpdrv <> ''
AND orpdat >= 2018001
UNION
SELECT d.orodr# orodr_,
orcust,
orldat,
CASE orpdat
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orpdat), 'YYYY-MM-DD')
END erdat2,
CASE orptim
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(char(orptim), 1, 2), ':'),
SUBSTRING(char(orptim), 3, 4))
END AS ertim2,
CASE orapdt
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orapdt), 'YYYY-MM-DD')
END ltdat2,
CASE oraptm
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(oraptm, 1, 2), ':'),
SUBSTRING(oraptm, 3, 4))
END AS lttim2,
CASE orddat
WHEN 0 THEN Varchar(0)
ELSE Varchar_format(CHAR(orddat), 'YYYY-MM-DD')
END dldat2,
CASE ordtim
WHEN 0 THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(ordtim, 1, 2), ':'),
SUBSTRING(ordtim, 3, 4))
END AS dltim2,
orestr,
ordv# ordv_,
orcons,
oreqty,
orspec,
orstp# orstp_,
orcomc,
( CASE
WHEN mmtotal IS NOT NULL THEN mmtotal
ELSE 0
END ) mmtotal,
orwgt,
orocty,
orost,
ordcty,
ordst,
orara asarea,
orpdrv oprdrv,
orld# orld_,
ordsp# ordsp_,
orshdt,
orshtm,
ornwpk,
( CASE
WHEN equipmentnumber IS NOT NULL THEN equipmentnumber
ELSE ' '
END ) EquipmentNumber,
( CASE
WHEN apptreq IS NOT NULL THEN apptreq
ELSE 'N'
END ) apptreq,
( CASE
WHEN apptmade IS NOT NULL THEN apptmade
ELSE 'N'
END ) apptmade,
( CASE
WHEN ununit IS NOT NULL THEN ununit
ELSE ' '
END ) UNUNIT,
( CASE
WHEN unsupr IS NOT NULL THEN unsupr
ELSE ' '
END ) asdrmgr,
( CASE
WHEN unfmgr IS NOT NULL THEN unfmgr
ELSE ' '
END ) asflmgr,
( CASE
WHEN untrl1 IS NOT NULL THEN untrl1
ELSE ' '
END ) UNTRL1
FROM iesqafile.opplan
LEFT OUTER JOIN iesqafile.order d
ON d.orodr# = opord#
LEFT OUTER JOIN ordermiles
ON mmord# = d.orodr#
LEFT OUTER JOIN firstequiprow
ON d.orodr# = oeord#
LEFT OUTER JOIN stopgroup
ON d.orodr# = stoporder
LEFT OUTER JOIN iesqafile.units
ON ununit = d.orpdrv
The first error is because in your 2 main SELECT statements (being UNIONed together) you have different column names - so the View doesn't know what to call them and is requiring you to explicitly name them e.g. the first column in each statement:
SELECT a.orodr# orodr_ ...
SELECT d.orodr# as ordddd ...
For the 2nd error, what is the datatype of the ORPTIM column?
I'm guessing that this type of construct is causing the issue:
CASE orptim
WHEN 0
THEN Varchar(0)
ELSE CONCAT(CONCAT(SUBSTRING(orptim, 1, 2), ':'), SUBSTRING(orptim, 3, 4))
If orptim is a number/decimal then "WHEN 0" will work but "SUBSTRING(orptim, 1, 2)" won't - as you can't substring a number. If orptim is a string then "WHEN 0" w=may be casuing problems.

Display Column value according to need in sql

if i have a column in which ten digit values occurs like Column A = 11111000 so how to show this value in sql like (List,Add,Edit,Delete,Export) in sql.
there is a condition means if first position have 1 then it show List, If second Position have 1 it show Add, third position have 1 then Edit, fourth position have 1 then Delete, fifth position have 1 then Export.
If the value is a string, you can do:
select stuff( ((case when substring(a, 1, 1) = 1 then ',List' else '' end) +
(case when substring(a, 2, 1) = 1 then ',Add' else '' end) +
. . .
), 1, 1, '')
The logic is similar for bitwise operators:
select stuff( ((case when a & 2^9 then ',List' else '' end) +
(case when 2 & 2^8 then ',Add' else '' end) +
. . .
), 1, 1, '')
Maybe Substring function can help you to identify these values
select
id, ColumnA,
case when substring(ColumnA,1,1) = '1' then 'X' end as List,
case when substring(ColumnA,2,1) = '1' then 'X' end as [Add],
case when substring(ColumnA,3,1) = '1' then 'X' end as Edit,
case when substring(ColumnA,4,1) = '1' then 'X' end as [Delete],
case when substring(ColumnA,5,1) = '1' then 'X' end as [Export]
from Table1
I update the query according to comment
select
id, ColumnA,
stuff(
case when substring(ColumnA,1,1) = '1' then ',List' else '' end +
case when substring(ColumnA,2,1) = '1' then ',Add' else '' end +
case when substring(ColumnA,3,1) = '1' then ',Edit' else '' end +
case when substring(ColumnA,4,1) = '1' then ',Delete' else '' end +
case when substring(ColumnA,5,1) = '1' then ',Export' else '' end
,1,1,''
)
from Table1

how to show field name if it set to true

I have a table with the 'ContentSubCategory' name.its fields are like below:
Id int
FaName nvarchar(50)
IsSpecial bit
IsPerishable bit
IsDanger bit
now I Want a query that shows list of content names and the attributes that are set to True.
for example:
Row ContentInfo
------------------------------------
1 animal - IsSpecial
2 Human Body - IsSpecial,IsPerishable
3 Danger Goods - IsSpecial,IsDanger
how can I do that?
select cast(FaName as varchar)+' - '+cast(
case when IsSpecial = 1 then 'IsSpecial,' else '' as varchar)+cast(
case when IsPerishable = 1 then 'IsPerishable,' else '' as varchar)+cast(
case when IsDanger = 1 then 'IsDanger' else '' as varchar)
from your_table
Try this and adjust to your own like.
You can also use STUFF():
SELECT
FaName
,ISNULL(
NULLIF(
STUFF(
CASE WHEN IsSpecial = 1 THEN ', IsSpecial' ELSE '' END
+ CASE WHEN IsPerishable =1 THEN ', IsPerishable' ELSE '' END
+ CASE WHEN IsDanger = 1 THEN ', IsDanger' ELSE '' END
, 1, 2, '')
,'')
, 'Unknown')
As Class
FROM TableName

How to count non-null/non-blank values in SQL

I have data like the following:
And what I want is to count the PONo, PartNo, and TrinityID fields with a value in them, and output data like this:
How can I do this counting in SQL?
select
Job_number, Item_code,
case when RTRIM(PONo) = '' or PONo is null then 0 else 1 end +
case when RTRIM(PartNo) = '' or PartNo is null then 0 else 1 end +
case when RTRIM(TrinityID) = '' or TrinityID is null then 0 else 1 end
as [Count]
from YourTable
Try this:
select Job_Number = t.Job_Number ,
Item_Code = t.Item_Code ,
"Count" = sum( case ltrim(rtrim(coalesce( PONo , '' ))) when '' then 0 else 1 end
+ case ltrim(rtrim(coalesce( PartNo , '' ))) when '' then 0 else 1 end
+ case ltrim(rtrim(coalesce( TrinityID , '' ))) when '' then 0 else 1 end
)
from dbo.my_table t
group by t.Job_Number , t.Item_Code
If you want to exclude data where all the tested fields are null or empty, add a having clause:
having sum( case ltrim(rtrim(coalesce( PONo , '' ))) when '' then 0 else 1 end
+ case ltrim(rtrim(coalesce( PartNo , '' ))) when '' then 0 else 1 end
+ case ltrim(rtrim(coalesce( TrinityID , '' ))) when '' then 0 else 1 end
) > 0
Easy!

Concatenating multiple CASE statements into one alias

After some previous help on how to approach a problem I am having with some legacy code, it seems like the best approach for my issue is to concatenate case statements to return a value I can parse out in PHP.
I am trying to do something like this, but it is returning many rows, and eventually getting this error:
Maximum stored procedure, function, trigger, or view nesting level
exceeded (limit 32).
SELECT org.org_id,
org.org_name_1,
Datename(YEAR, member.enroll_date) AS enroll_year,
Max(CASE
WHEN board.member_from IS NULL THEN 0
ELSE 1
END) AS board_member,
CASE
WHEN ( org.delete_reason = 'OUT'
AND org.org_delete_flag = 'Y'
AND org.org_status_flag = 'C' ) THEN 'out_of_business|'
ELSE ''
END + CASE
WHEN ( stat.carrier = 'BS'
AND stat.status_id IS NOT NULL
AND stat.termination_date IS NULL
AND stat.flat_dues > 0 ) THEN 'insurance_member|'
ELSE ''
END + CASE
WHEN ( stat.carrier = 'BS'
AND stat.status_id IS NOT NULL
AND stat.termination_date IS NULL
AND stat.flat_dues = 0
AND member.status_flag IN( 'C', 'P' ) ) THEN 'insurance_product|'
ELSE ''
END + CASE
WHEN ( member.enroll_date IS NOT NULL
AND member.status_flag NOT IN( 'C', 'P' ) ) THEN 'member_since|'
ELSE ''
END + CASE
WHEN ( org.org_relationship_parent = 'Y'
AND org.dues_category = 'MBR'
AND org.org_status_flag = 'R' ) THEN 'subsidiary_member|'
ELSE ''
END + CASE
WHEN ( org.org_misc_data_9 = 'PAC' ) THEN 'pac|'
ELSE ''
END + CASE
WHEN ( org.dues_category = 'PART' ) THEN 'partner_member|'
ELSE ''
END + CASE
WHEN ( org.dues_category = 'FREE'
AND org.org_status_flag = 'P' ) THEN 'associate_member|'
ELSE ''
END
--ELSE 'non_member'
--END
AS org_status,
60 AS expires_in,
CASE
WHEN stat.dues_type = 'M' THEN
CASE
WHEN ( stat.termination_date IS NULL ) THEN ( stat.flat_dues )
ELSE 0
END
ELSE
CASE
WHEN ( member.payments = 0 ) THEN member.dues_billed_annual
ELSE member.payments
END
END AS dues_level,
CASE
WHEN ( org.affiliate_code = 'PCCE'
AND org.dues_category = 'MBR'
AND org.org_status_flag = 'R' ) THEN 1
ELSE 0
END AS pcce_membr,
-- '$'+CONVERT(VARCHAR,#dues) AS dues_level,
Ltrim(#product_level) AS product_level,
Ltrim(#involve_level) AS involvement_level
FROM organiz AS org
LEFT JOIN affilbil AS member
ON member.status_id = org.org_id
AND member.dues_category = 'MBR'
LEFT JOIN individu AS ind
ON ind.org_id = org.org_id
LEFT JOIN commembr AS board
ON board.status_id = ind.ind_id
AND board.committee_code = '5'
AND board.member_to IS NULL
LEFT JOIN statinsmorn AS stat
ON stat.status_id = org.org_id
AND stat.carrier = 'BS'
AND stat.planz = 'PCI'
WHERE org.org_id = #org_id
GROUP BY org.org_id,
org.org_name_1,
member.enroll_date,
org.delete_reason,
org.org_status_flag,
org.org_delete_flag,
stat.status_id,
stat.flat_dues,
stat.dues_type,
stat.termination_date,
org.org_misc_data_9,
org_relationship_parent,
org.dues_category,
member.status_flag,
member.dues_billed_annual,
member.payments,
stat.carrier,
org.Affiliate_Code
Well, this is embarrassing.
When I was making my changes to the stored procedure, I had inadvertently placed a call to the same procedure at the bottom. So I was recursively calling the same procedure over and over again. DOH.