May 5, 2014 at 12:41 pm
In the below procedure definition, i need to find a way parse the definition and get the list of places where the where clause is being used.
SELECT DISTINCT
FC.CASE_ID,
UPPER(FC.CASE_NUMBER) AS CASE_NUMBER,
UPPER(REPLACE(FC.CASE_SHORT_TITLE,CHAR(13)+CHAR(10),'')) AS CASE_SHORT_TITLE,
FC.CASE_STATUS_DESCR,
FC.CASE_TYP_DESC, FC.CASE_SUB_TYP_DESC,
UPPER(AJ.DISPLAYNAME) AS JUDGE,
UPPER(PP.DISPLAYNAME) AS PARTY_DISPLAYNAME,
UPPER(AP.ATTORNEY_DISPLAYNAME)AS ATTORNEY_DISPLAYNAME ,
CASE WHEN RC_PARENT.PARENT_CASE_ID IS NOT NULL
THEN 'PARENT'
ELSE
CASE WHEN RC_CHILD.CHILD_CASE_ID IS NOT NULL
THEN 'CHILD'
ELSE NULL
END
END AS CONSOLIDATED,
PP.PARTY_STATUS_TYP_DESC,
LAST_EVENT_DT = CONVERT(VARCHAR(15),(SELECT TOP 1 FILING_DT FROM SW_ACM_V_EVENT_CASE WHERE (CASE_ID=FC.CASE_ID AND FILING_DT < GETDATE())ORDER BY FILING_DT DESC),101),
LAST_EVENT_ENTRY_DESC = UPPER((SELECT TOP 1 EVENT_ENTRY_DESC FROM SW_ACM_V_EVENT_CASE WHERE CASE_ID=FC.CASE_ID and void_event ='N' ORDER BY FILING_DT DESC )),
LAST_SCHEDULED_DT = CONVERT(VARCHAR(15),(SELECT TOP 1 ITEM_START_DT FROM ACC_SESSION_ITEM WHERE (CASE_ID=FC.CASE_ID AND ITEM_START_DT < GETDATE()) ORDER BY ITEM_START_DT DESC),101),
LAST_TICKLER_DT = CONVERT(VARCHAR(15), (SELECT TOP 1 TERMINATING_DATE FROM SW_ACM_V_TICKLERS_NOTSATISFIED WHERE (CASE_ID=FC.CASE_ID AND TERMINATING_DATE < GETDATE()) ORDER BY TERMINATING_DATE DESC),101)
FROM
AZLJ_ACM_V_FACTS_CASE AS FC
LEFT OUTER JOIN AZLJ_ACM_V_JUDGE AJ ON AJ.JUDGE_CD = FC.JUDGE_CD
LEFT OUTER JOIN ACM_RELATED_CASES RC_PARENT ON RC_PARENT.PARENT_CASE_ID=fc.CASE_ID AND RC_PARENT.CASE_RELATED_TYP_ID=(SELECT [VALUE] FROM CFG_ELEMENTS WHERE ELEMENT_NAME='REPORT_CONSOLIDATEDCASES_CASERELATEDTYPID')
LEFT OUTER JOIN ACM_RELATED_CASES RC_CHILD ON RC_CHILD.CHILD_CASE_ID=FC.CASE_ID AND RC_CHILD.CASE_RELATED_TYP_ID=(SELECT [VALUE] FROM CFG_ELEMENTS WHERE ELEMENT_NAME ='REPORT_CONSOLIDATEDCASES_CASERELATEDTYPID')
LEFT OUTER JOIN AZLJ_ACM_V_PERS_PARTY AS PP ON PP.CASE_ID = FC.CASE_ID AND PP.PARTY_ROLE_TYP_ID NOT IN (SELECT PARTY_ROLE_TYP_ID FROM ACM_PARTY_ROLE_TYP WHERE ROLE_FOR_ATT = 'Y')
LEFT OUTER JOIN SW_ACM_V_ATTORNEY_PARTY AS AP ON AP.PARTY_ID = PP.PARTY_ID AND AP.PARTY_ROLE_TYP_CD = 'Y'
LEFT OUTER JOIN SW_ACM_V_TICKLERS_NOTSATISFIED AS TNS ON TNS.CASE_ID = FC.CASE_ID
LEFT OUTER JOIN ACM_TICKLER_TYP_EVENT_TYP_MAP AS TTETM ON TTETM.TICKLER_TYP_ID =TNS.TICKLER_TYP_ID
WHERE
((TNS.SATISFACTION_EVENT_ENTRY_ID IS NULL) AND (TNS.TERMINATING_DATE < GETDATE()) AND (ISNULL(TTETM.NEXT_EVENT_ENTRY_TYP_ID,0) = 0))
AND (FC.NEXT_SESSION_DATE IS NULL OR FC.NEXT_SESSION_DATE < GETDATE() )
AND FC.CASE_ID NOT IN (SELECT CASE_ID FROM ACC_SESSION_ITEM WHERE ITEM_START_DT > GETDATE())
AND (FC.CASE_STATUS_TYP_ID NOT IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME='REPORT_ACTIONPEND_NOTINCASESTSID'))
AND ((PP.PARTY_STATUS_TYP_ID NOT IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME='REPORT_INACTIVE_PARTYSTSID'))
OR (PP.PARTY_STATUS_TYP_ID IS NULL))
AND(FC.CASE_ID IN (SELECT DISTINCT CASE_ID FROM SW_ACM_V_TICKLERS_NOTSATISFIED WHERE TERMINATING_DATE < GETDATE()
EXCEPT SELECT DISTINCT CASE_ID FROM SW_ACM_V_TICKLERS_NOTSATISFIED WHERE TERMINATING_DATE > GETDATE()))
In the above query there are more than one places and the where clause may not have the same string the where clause it can be with a space between the "=" and the value in single quotes.
Result set should be in the below format:
TABLE NAME Column Name VALUE
CFG_ELEMENTS ELEMENT_NAME REPORT_CONSOLIDATEDCASES_CASERELATEDTYPID
May 5, 2014 at 12:51 pm
Any whitespace (blanks, tabs, line ends, comments /* */) around an "=" sign in a where clause are ignored by SQL. You can have one, ten, one hundred etc., or none at all.
May 5, 2014 at 12:56 pm
I'm not sure what your saying here.
Please explain. Thanks,
May 5, 2014 at 1:05 pm
I mean that the following WHERE clauses are equivalent:
1. No space
WHERE a=b
2. Some spaces
WHERE a = b
3. Some lines between
WHERE
a
=
b
May 5, 2014 at 1:12 pm
ohh ok, that is good if they are ignored by SQL.
But, how do i get the list of where clauses from the definition.
May 5, 2014 at 1:41 pm
http://stackoverflow.com/questions/6008839/bison-flex-sql-parser
http://stackoverflow.com/questions/8656926/sql-lex-yacc-grammar
edit:
this looks interesting too, although I couldn't discern with my short read if you could use it for your case:
May 5, 2014 at 2:35 pm
I don't think this solves my question.
May 5, 2014 at 2:41 pm
vamsye (5/5/2014)
I don't think this solves my question.
What exactly is the question? It seems like you want a list of filtering predicates? The sql you posted has multiple select statements. Given the sql you posted what is the desired output?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 5, 2014 at 2:47 pm
For anybody else wanting to view this query I formatted it.
SELECT DISTINCT FC.CASE_ID
,UPPER(FC.CASE_NUMBER) AS CASE_NUMBER
,UPPER(REPLACE(FC.CASE_SHORT_TITLE, CHAR(13) + CHAR(10), '')) AS CASE_SHORT_TITLE
,FC.CASE_STATUS_DESCR
,FC.CASE_TYP_DESC
,FC.CASE_SUB_TYP_DESC
,UPPER(AJ.DISPLAYNAME) AS JUDGE
,UPPER(PP.DISPLAYNAME) AS PARTY_DISPLAYNAME
,UPPER(AP.ATTORNEY_DISPLAYNAME) AS ATTORNEY_DISPLAYNAME
,CASE
WHEN RC_PARENT.PARENT_CASE_ID IS NOT NULL
THEN 'PARENT'
ELSE CASE
WHEN RC_CHILD.CHILD_CASE_ID IS NOT NULL
THEN 'CHILD'
ELSE NULL
END
END AS CONSOLIDATED
,PP.PARTY_STATUS_TYP_DESC
,LAST_EVENT_DT = CONVERT(VARCHAR(15), (
SELECT TOP 1 FILING_DT
FROM SW_ACM_V_EVENT_CASE
WHERE (
CASE_ID = FC.CASE_ID
AND FILING_DT < GETDATE()
)
ORDER BY FILING_DT DESC
), 101)
,LAST_EVENT_ENTRY_DESC = UPPER((
SELECT TOP 1 EVENT_ENTRY_DESC
FROM SW_ACM_V_EVENT_CASE
WHERE CASE_ID = FC.CASE_ID
AND void_event = 'N'
ORDER BY FILING_DT DESC
))
,LAST_SCHEDULED_DT = CONVERT(VARCHAR(15), (
SELECT TOP 1 ITEM_START_DT
FROM ACC_SESSION_ITEM
WHERE (
CASE_ID = FC.CASE_ID
AND ITEM_START_DT < GETDATE()
)
ORDER BY ITEM_START_DT DESC
), 101)
,LAST_TICKLER_DT = CONVERT(VARCHAR(15), (
SELECT TOP 1 TERMINATING_DATE
FROM SW_ACM_V_TICKLERS_NOTSATISFIED
WHERE (
CASE_ID = FC.CASE_ID
AND TERMINATING_DATE < GETDATE()
)
ORDER BY TERMINATING_DATE DESC
), 101)
FROM AZLJ_ACM_V_FACTS_CASE AS FC
LEFT JOIN AZLJ_ACM_V_JUDGE AJ ON AJ.JUDGE_CD = FC.JUDGE_CD
LEFT JOIN ACM_RELATED_CASES RC_PARENT ON RC_PARENT.PARENT_CASE_ID = fc.CASE_ID
AND RC_PARENT.CASE_RELATED_TYP_ID = (
SELECT [VALUE]
FROM CFG_ELEMENTS
WHERE ELEMENT_NAME = 'REPORT_CONSOLIDATEDCASES_CASERELATEDTYPID'
)
LEFT JOIN ACM_RELATED_CASES RC_CHILD ON RC_CHILD.CHILD_CASE_ID = FC.CASE_ID
AND RC_CHILD.CASE_RELATED_TYP_ID = (
SELECT [VALUE]
FROM CFG_ELEMENTS
WHERE ELEMENT_NAME = 'REPORT_CONSOLIDATEDCASES_CASERELATEDTYPID'
)
LEFT JOIN AZLJ_ACM_V_PERS_PARTY AS PP ON PP.CASE_ID = FC.CASE_ID
AND PP.PARTY_ROLE_TYP_ID NOT IN (
SELECT PARTY_ROLE_TYP_ID
FROM ACM_PARTY_ROLE_TYP
WHERE ROLE_FOR_ATT = 'Y'
)
LEFT JOIN SW_ACM_V_ATTORNEY_PARTY AS AP ON AP.PARTY_ID = PP.PARTY_ID
AND AP.PARTY_ROLE_TYP_CD = 'Y'
LEFT JOIN SW_ACM_V_TICKLERS_NOTSATISFIED AS TNS ON TNS.CASE_ID = FC.CASE_ID
LEFT JOIN ACM_TICKLER_TYP_EVENT_TYP_MAP AS TTETM ON TTETM.TICKLER_TYP_ID = TNS.TICKLER_TYP_ID
WHERE (
(TNS.SATISFACTION_EVENT_ENTRY_ID IS NULL)
AND (TNS.TERMINATING_DATE < GETDATE())
AND (ISNULL(TTETM.NEXT_EVENT_ENTRY_TYP_ID, 0) = 0)
)
AND (
FC.NEXT_SESSION_DATE IS NULL
OR FC.NEXT_SESSION_DATE < GETDATE()
)
AND FC.CASE_ID NOT IN (
SELECT CASE_ID
FROM ACC_SESSION_ITEM
WHERE ITEM_START_DT > GETDATE()
)
AND (
FC.CASE_STATUS_TYP_ID NOT IN (
SELECT DATA_VALUE
FROM AICMS_REPORT_PARAMETERS
WHERE VARIABLE_NAME = 'REPORT_ACTIONPEND_NOTINCASESTSID'
)
)
AND (
(
PP.PARTY_STATUS_TYP_ID NOT IN (
SELECT DATA_VALUE
FROM AICMS_REPORT_PARAMETERS
WHERE VARIABLE_NAME = 'REPORT_INACTIVE_PARTYSTSID'
)
)
OR (PP.PARTY_STATUS_TYP_ID IS NULL)
)
AND (
FC.CASE_ID IN (
SELECT DISTINCT CASE_ID
FROM SW_ACM_V_TICKLERS_NOTSATISFIED
WHERE TERMINATING_DATE < GETDATE()
EXCEPT
SELECT DISTINCT CASE_ID
FROM SW_ACM_V_TICKLERS_NOTSATISFIED
WHERE TERMINATING_DATE > GETDATE()
)
)
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 6, 2014 at 9:19 am
TABLE NAME Column Name VALUE
CFG_ELEMENTS ELEMENT_NAME REPORT_CONSOLIDATEDCASES_CASERELATEDTYPID
May 6, 2014 at 9:25 am
vamsye (5/6/2014)
TABLE NAME Column Name VALUECFG_ELEMENTS ELEMENT_NAME REPORT_CONSOLIDATEDCASES_CASERELATEDTYPID
???
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 6, 2014 at 9:30 am
result set
May 6, 2014 at 9:32 am
vamsye (5/6/2014)
result set
The problem is that we can't see your screen. We have no idea what you are trying to do.
In order to help we will need a few things:
1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data
Please take a few minutes and read the first article in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 6, 2014 at 9:58 am
CREATE TABLE sqlText (ID int , line NVARCHAR(MAX),referenced_entity_name VARCHAR(1000) )
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8712,'CREATE view [dbo].[AZLJ_RPT_V_STAT_CVLDISPOSITION] as
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8713,'/************************************************************************************
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8714,'Name:AZLJ_RPT_V_STAT_CVLDISPOSITION
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8715,'Created By:Suganya
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8716,'Created Date:11/07/2008
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8717,'Purpose:Statistical Report : Civil - Manner of Disposition
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8718,'Modifications:02/16/2009 - Suganya - Else part added
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8719,' 05/01/2010 - Kali - Added the Inner Join to EVENT_ENTRY
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8720,'************************************************************************************/
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8721,'
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8722,'SELECT
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8723,'CASE_TYP_DESC,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8724,'CASE_SUB_TYP_DESC,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8725,'FC.CASE_NUMBER,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8726,'CONVERT(VARCHAR,DISPOSITION_DT,101) AS DISPOSITION_DT,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8727,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC1'')--(1000045,1000046)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8728,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8729,'END AS C1,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8730,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC2'')--(1000037)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8731,' THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8732,'END AS C2,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8733,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC3'')--(1000038)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8734,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8735,'END AS C3,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8736,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC4'')--(1000100)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8737,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8738,'END AS C4,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8739,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC5'')--(1000103)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8740,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8741,'END AS C5,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8742,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC6'')--(1000097)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8743,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8744,'END AS C6,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8745,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC7'') --(1000041,1000043,1000044)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8746,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8747,'END AS C7,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8748,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC8'') --(1000083,1000084,1000085,1000086)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8749,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8750,'END AS C8,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8751,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC10'') --(1000102)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8752,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8753,'END AS C10,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8754,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC11'') --(1000099)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8755,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8756,'END AS C11,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8757,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC13'') --(1000036)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8758,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8759,'END AS C13,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8760,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC14'') --(1000098)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8761,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8762,'END AS C14,
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8763,'CASE WHEN J.DISPOSITION_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVLDISPOSITIONIDC17'') --(1000039)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8764,'THEN COUNT(FC.CASE_ID) ELSE 0
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8765,'END AS C17
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8766,'
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8767,'
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8768,'FROM AZLJ_ACM_V_FACTS_CASE FC
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8769,' INNER JOIN ACM_JUDGEMENT J ON J.CASE_ID = FC.CASE_ID
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8770,'--Kali Added this to make sure the event is not void
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8771,' INNER JOIN ACM_EVENT_ENTRY AE ON AE.EVENT_ENTRY_ID=J.EVENT_ENTRY_ID AND AE.VOID=''N''
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8772,'
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8773,'WHERE
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8774,' FC.COURT_TYP_ID IN (SELECT DATA_VALUE FROM AICMS_REPORT_PARAMETERS WHERE VARIABLE_NAME =''RPT_STAT_CVL_COURTYPID'') --(1000002)
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8775,'
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8776,'AND
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8777,' J.DISPOSITION_ID IS NOT NULL
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8778,'AND
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8779,'CASE_SUB_TYP_DESC IS NOT NULL
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8780,'
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8781,'
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
INSERT INTO [sqlText] ([Id],[line],[referenced_entity_name])VALUES(8782,'GROUP BY CASE_TYP_DESC,CASE_SUB_TYP_DESC,J.DISPOSITION_ID,DISPOSITION_DT,FC.CASE_NUMBER
','AZLJ_RPT_V_STAT_CVLDISPOSITION')
RESULT SET
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC1' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC2' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC3' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC4' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC5' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC6' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC7' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC8' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC10' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC1' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC11' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC14' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVLDISPOSITIONIDC17' AS VALUE
UNION ALL
SELECT 'AICMS_REPORT_PARAMETERS' AS TABLE_NAME, 'VARIABLE_NAME' AS COLUMN_NAME, 'RPT_STAT_CVL_COURTYPID' AS VALUE
May 6, 2014 at 11:12 am
I had a feeling that was what you wanted. There is < 0.00% percent chance you will get this right. I don't mean any disrespect but you are trying to parse an extremely complicated sql query and determine which pieces of a where clause belong to which table. There may be some third party tools that can parse this but just using t-sql I would be shocked if anybody could get this correct.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply