Data Populated in a single row??
Hi,
I have a requirement as follows:
Suppose there is a column "A". There many be "n" no. of records for that column "A"
I want the code logic for this to sum up all the "n" no. of records,which is of type amount and to be populated in a single row.
Ex :
Column A
7867.68
5658.65
566765.44
n
like this "n" no. of records would be populated (at the runtime).
I need the output as :
Column A
SUM(7867.68 + 5658.65 + 566765.44 + .......n) in a single row.
Immediate reply would be greatly appreciated.
Thanks in advance,
Regards,
Vamc
Message was edited by: Manish Kumar : Do not ask for urgent/immediate reply
Hi vamshi,
Both Collect and AT END OF.... END AT, we can use for the above requirement.
Collect Statement:
LOOP AT IT_TABLE into WA_TABLE.
COLLECT WA_TABLE TO IT_FINAL.
ENDLOOP.
Control Break Statement (AT END OF... END AT):
If you are using Control break statement, before LOOP Statement, sort the table as shown below.
"Data Declarations
DATA: L_END TYPE I VALUE 0,
L_COUNT TYPE I VALUE 0.
"Sort the Internal Table
SORT IT_TABLE BY MATNR.
LOOP AT IT_TABLE INTO WA_TABLE.
L_COUNT = L_COUNT + WA_TABLE-VALUE.
AT END OF MATNR.
L_END = 1.
ENDAT.
IF L_END = 1.
MOVE CORRESPONDING WA_TABLE to WA_FINAL.
"Assign Count value
WA_FINAL-TOTAL = L_COUNT.
"Append the value to Internal Table
APPEND WA_FINAL TO IT_FINAL.
"Clear WA & Count
CLEAR: WA_FINAL,
L_COUNT,
L_END.
ENDIF.
ENDLOOP.
Regards
Rajkumar Narasimman
Similar Messages
-
How to aggregate a column based date column (for weekly single row)?
How to aggregate a column based date column (for weekly single row)?
Hi,
Consider the below statement for daily bases which is ok
SELECT ID, DATE, SUM(AMOUNT) FROM TABLE_NAME GROUP BY ID, DATE ORDER BY ID, DATE
The same like the above statement, I want output on weekly, fortnightly, and monthly bases, How to do this? Need your help... -
Group By element ID and continuous date range as a single row - URGENT!!!!
Hi All,
I have a source table and a target table.
Source Table Target Table
Element ID Period_dt Element ID Effective date End date
DD001 200901 DD001 200901 200903
DD001 200902 DD001 200906 200908
DD001 200903 DD002 200801 200803
DD001 200906
DD001 200907
DD001 200908
DD002 200801
DD002 200802
DD002 200803
I want the result as in the target table. Basically, continuous date range should be grouped and shown as single row even it falls under the same elment_id.
I have tried the LAG and LEAD function and RANK function as well but unsuccessful.
I was able to get like this in the target table using MIN and MAX function.
DD001 200901 200908
DD002 200801 200803
For DD001, you can see there is a break in the months. 200901 - 200903 and 200906 - 200908. we are missing 4th,5th month. 1 to 3rd month and 6th to 8th month should be grouped and shown as separate rows in the target table for the same DD001 element_ID
I will post the SQL query tommorrow. Please give your suggestions.
Regards
BalajiThanks guys. It worked perfectly. I apologize for using the 'U' word. This is my first post here.
select prod_element_cd,
min(period_dt) effective_date,
max(Last_day(period_dt)) end_date,
SUM(Fixed_factor),
SUM(var_factor),
val1
from (
select prod_element_cd, period_dt,Fixed_factor,var_factor, val, last_value(val ignore nulls) over(partition by prod_element_cd order by period_dt) val1
from (
select prod_element_cd,
period_dt,
NVL(Fixed,0) Fixed_factor,
NVL(variable,0) var_factor,
lag(period_dt) over(partition by prod_element_cd order by period_dt) dt,
case when add_months(period_dt,-1) = lag(period_dt) over(partition by prod_element_cd order by period_dt)
then null
else rownum end val
from pmax_land.TMP_COST_CASH_STD_INPUT)
group by prod_element_cd, val1
order by prod_element_cd
The above query pulls the below result
PROD_ELEMENT_CD EFFECTIVE_DATE END_DATE FIXED VARIABLE VAL1
DDA001 01/01/2009 03/31/2009 4.20 7.62 1.00
DDA001 06/01/2009 11/30/2009 4.80 0.72 10.00
DDA001 01/01/2010 01/31/2010 0.75 0.50 13.00
DDA002 07/01/2008 09/30/2008 2.40 0.36 11.00
DDA002 02/01/2008 03/31/2008 1.50 1.00 14.00
one more logic added to the requirement
for each occurance, for eg: DDA001, the last row of DDA001 should be taken and the end_date of that should be hardcoded to 12/31/9999
here we have two cases
last row for DDA001 end_date
DDA001 01/01/2010 01/31/2010 0.75 0.50 13.00
end date is 01/31/2010 for this above row of DDA001. It should be hardcoded to 12/31/9999
similarly
last row for DDA002 end_date
DDA002 02/01/2008 03/31/2008 1.50 1.00 14.00
end date is 03/31/2008 for this above row of DDA002. It should be hardcoded to 12/31/9999
Similarly for DDA003,DDA004.......... etc
Thanks for your previous replies. Please give your suggestions.
Regards
Balaji
Edited by: user12119826 on Oct 27, 2009 11:49 PM -
Data Merge Repeating a Single Row
I've been trying to use data merge and found it very useful. The only problem is, for no reason I can see, data merge is repeating row 8 from my document. Here is what happens:
I create a csv file from a 22 row Excel spreadsheet.
I use data merge to create a multiple record document. The preview looks fine, all records are correct!
I create the document, and all of a sudden almost all the entries use the data from row 8. The document contains the correct number of entries, they are just almost all a repeat of row 8.
And here something strange - row 1-3 show up as row 8, then rows 4-9 show up fine, and then the rest (up to the final row 22) show up as row 8 again.
I've tried switch row 8 with another row, but no matter what the content is it continues to repeat row 8 - including if it is blank. Any help would be appreciated. I am new to data merge so I may be doing something airheaded.What version of ID are you using?
There were some issues like this that cropped up in early releases of CS4, so be sure you've downloaded the patches. If that still doesn't solve the problem, it could be an odd character or somthing similar (too many fields or not enough fields) in one of the records, so open the data file in a plain text editor, look it over, and resave.
Unfortunately, I've also seen data files that just didn't work in CS4, for no reason anyone was able to find. -
Merging Multiple Rows into a single Row
I've read a number of posts with no real good answers or answers that might be good for tables with 3 columns of data. I have a table with 33 columns that will all need to be combined. A little history. Apparently in production the Primary Key Constraint
was dropped which allowed some duplicate data into the table. Now they want me to squish the records together to fix it.
Sorry I couldn't include the screen shot of the data, MSDN says my account isn't verified...
My requirements when I'm putting them together, CERElibilityID is a unique column. This is a sticky problem because in the related tables it is only one of the parent records gets child records related to it.
I just want to keep the one that has the child records in CERPrepActivity table. If there are no child records then the rule will be like all the other records with data.
If a field is null and another record has data we take the record that has data.
If multiple records have data we take the record that has the highest "ModifiedOn" timestamp column value.
I feel like I'm asking a lot, but I'm in a bit of a bind and I've spent the morning Googling and have come up with nothing
Thank you for any help the community can provide and the more specific you can be the better. I'm not a DBA or SQL guru by any stretch so I'm way out of my element.
ThanksUsing the systables, you can get information about your table. I put these together:
SELECT '
LEFT OUTER JOIN #CEREligibility ['+c.name+']
ON s.caseID = ['+c.name+'].caseID
AND s.modifiedOn = ['+c.name+'].modifiedOn
AND ['+c.name+'].['+c.name+'] = (SELECT TOP 1 ['+c.name+'] FROM #CEREligibility WHERE caseID = s.caseID AND ['+c.name+'] IS NOT NULL ORDER BY ModifiedOn)
AND ['+c.name+'].['+c.name+'] IS NOT NULL'
FROM tempdb.sys.objects o
INNER JOIN tempdb.sys.columns c
ON o.object_id = c.object_id
AND o.name LIKE '#CEREligibility%'
SELECT '['+c.name+'].['+c.name+'] AS ['+c.name+'], '
FROM tempdb.sys.objects o
INNER JOIN tempdb.sys.columns c
ON o.object_id = c.object_id
AND o.name LIKE '#CEREligibility%'
On my test system I created your table as a temp table named #CEREligibility.
The first of these two queries generates LEFT OUT JOIN SQL for a self join. Because we're using the columns systable, a LOJ for each column is generated.
The second, produces a select list.
Putting the two together like so, and adding a FROM and GROUP BY gives us:
SELECT
MAX([CEREligibilityId].[CEREligibilityId]) AS [CEREligibilityId], s.[CaseId], MAX([M2Eligibility].[M2Eligibility]) AS [M2Eligibility], MAX([CDREligibility].[CDREligibility]) AS [CDREligibility], MAX([M2Comments].[M2Comments]) AS [M2Comments], MAX([M2CommentsRtf].[M2CommentsRtf]) AS [M2CommentsRtf], MAX([CDRComments].[CDRComments]) AS [CDRComments], MAX([CDRCommentsRtf].[CDRCommentsRtf]) AS [CDRCommentsRtf], MAX([RIAWA].[RIAWA]) AS [RIAWA], MAX([RIAWADate].[RIAWADate]) AS [RIAWADate], MAX([EducationAndTraining].[EducationAndTraining]) AS [EducationAndTraining], MAX([EducationAndTrainingDate].[EducationAndTrainingDate]) AS [EducationAndTrainingDate], MAX([Internship].[Internship]) AS [Internship], MAX([InternshipDate].[InternshipDate]) AS [InternshipDate], MAX([Apprenticeship].[Apprenticeship]) AS [Apprenticeship], MAX([ApprenticeshipDate].[ApprenticeshipDate]) AS [ApprenticeshipDate], MAX([Entrepreneurship].[Entrepreneurship]) AS [Entrepreneurship], MAX([EntrepreneurshipDate].[EntrepreneurshipDate]) AS [EntrepreneurshipDate], MAX([EmploymentPrep].[EmploymentPrep]) AS [EmploymentPrep], MAX([EmploymentPrepDate].[EmploymentPrepDate]) AS [EmploymentPrepDate], MAX([OTPrep].[OTPrep]) AS [OTPrep], MAX([OTPrepDate].[OTPrepDate]) AS [OTPrepDate], MAX([ExitInterview].[ExitInterview]) AS [ExitInterview], MAX([ExitInterviewDate].[ExitInterviewDate]) AS [ExitInterviewDate], MAX([CreatedOn].[CreatedOn]) AS [CreatedOn], MAX([CreatedBy].[CreatedBy]) AS [CreatedBy], MAX([ModifiedOn].[ModifiedOn]) AS [ModifiedOn], MAX([ModifiedBy].[ModifiedBy]) AS [ModifiedBy], MAX([BCPermInEligibility].[BCPermInEligibility]) AS [BCPermInEligibility], MAX([CCPermInEligibility].[CCPermInEligibility]) AS [CCPermInEligibility], MAX([M2EligibilityDate].[M2EligibilityDate]) AS [M2EligibilityDate], MAX([CDREligibilityDate].[CDREligibilityDate]) AS [CDREligibilityDate], MAX([ExitSeparationCode].[ExitSeparationCode]) AS [ExitSeparationCode], MAX([ExitSeparationSubCode].[ExitSeparationSubCode]) AS [ExitSeparationSubCode]
FROM #CEREligibility s
LEFT OUTER JOIN #CEREligibility [CEREligibilityId]
ON s.caseID = [CEREligibilityId].caseID
AND s.modifiedOn = [CEREligibilityId].modifiedOn
AND [CEREligibilityId].[CEREligibilityId] = (SELECT TOP 1 [CEREligibilityId] FROM #CEREligibility WHERE caseID = s.caseID AND [CEREligibilityId] IS NOT NULL ORDER BY ModifiedOn)
AND [CEREligibilityId].[CEREligibilityId] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CaseId]
ON s.caseID = [CaseId].caseID
AND s.modifiedOn = [CaseId].modifiedOn
AND [CaseId].[CaseId] = (SELECT TOP 1 [CaseId] FROM #CEREligibility WHERE caseID = s.caseID AND [CaseId] IS NOT NULL ORDER BY ModifiedOn)
AND [CaseId].[CaseId] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [M2Eligibility]
ON s.caseID = [M2Eligibility].caseID
AND s.modifiedOn = [M2Eligibility].modifiedOn
AND [M2Eligibility].[M2Eligibility] = (SELECT TOP 1 [M2Eligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Eligibility] IS NOT NULL ORDER BY ModifiedOn)
AND [M2Eligibility].[M2Eligibility] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CDREligibility]
ON s.caseID = [CDREligibility].caseID
AND s.modifiedOn = [CDREligibility].modifiedOn
AND [CDREligibility].[CDREligibility] = (SELECT TOP 1 [CDREligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibility] IS NOT NULL ORDER BY ModifiedOn)
AND [CDREligibility].[CDREligibility] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [M2Comments]
ON s.caseID = [M2Comments].caseID
AND s.modifiedOn = [M2Comments].modifiedOn
AND [M2Comments].[M2Comments] = (SELECT TOP 1 [M2Comments] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Comments] IS NOT NULL ORDER BY ModifiedOn)
AND [M2Comments].[M2Comments] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [M2CommentsRtf]
ON s.caseID = [M2CommentsRtf].caseID
AND s.modifiedOn = [M2CommentsRtf].modifiedOn
AND [M2CommentsRtf].[M2CommentsRtf] = (SELECT TOP 1 [M2CommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [M2CommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
AND [M2CommentsRtf].[M2CommentsRtf] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CDRComments]
ON s.caseID = [CDRComments].caseID
AND s.modifiedOn = [CDRComments].modifiedOn
AND [CDRComments].[CDRComments] = (SELECT TOP 1 [CDRComments] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRComments] IS NOT NULL ORDER BY ModifiedOn)
AND [CDRComments].[CDRComments] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CDRCommentsRtf]
ON s.caseID = [CDRCommentsRtf].caseID
AND s.modifiedOn = [CDRCommentsRtf].modifiedOn
AND [CDRCommentsRtf].[CDRCommentsRtf] = (SELECT TOP 1 [CDRCommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRCommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
AND [CDRCommentsRtf].[CDRCommentsRtf] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [RIAWA]
ON s.caseID = [RIAWA].caseID
AND s.modifiedOn = [RIAWA].modifiedOn
AND [RIAWA].[RIAWA] = (SELECT TOP 1 [RIAWA] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWA] IS NOT NULL ORDER BY ModifiedOn)
AND [RIAWA].[RIAWA] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [RIAWADate]
ON s.caseID = [RIAWADate].caseID
AND s.modifiedOn = [RIAWADate].modifiedOn
AND [RIAWADate].[RIAWADate] = (SELECT TOP 1 [RIAWADate] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWADate] IS NOT NULL ORDER BY ModifiedOn)
AND [RIAWADate].[RIAWADate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EducationAndTraining]
ON s.caseID = [EducationAndTraining].caseID
AND s.modifiedOn = [EducationAndTraining].modifiedOn
AND [EducationAndTraining].[EducationAndTraining] = (SELECT TOP 1 [EducationAndTraining] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTraining] IS NOT NULL ORDER BY ModifiedOn)
AND [EducationAndTraining].[EducationAndTraining] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EducationAndTrainingDate]
ON s.caseID = [EducationAndTrainingDate].caseID
AND s.modifiedOn = [EducationAndTrainingDate].modifiedOn
AND [EducationAndTrainingDate].[EducationAndTrainingDate] = (SELECT TOP 1 [EducationAndTrainingDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTrainingDate] IS NOT NULL ORDER BY ModifiedOn)
AND [EducationAndTrainingDate].[EducationAndTrainingDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [Internship]
ON s.caseID = [Internship].caseID
AND s.modifiedOn = [Internship].modifiedOn
AND [Internship].[Internship] = (SELECT TOP 1 [Internship] FROM #CEREligibility WHERE caseID = s.caseID AND [Internship] IS NOT NULL ORDER BY ModifiedOn)
AND [Internship].[Internship] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [InternshipDate]
ON s.caseID = [InternshipDate].caseID
AND s.modifiedOn = [InternshipDate].modifiedOn
AND [InternshipDate].[InternshipDate] = (SELECT TOP 1 [InternshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [InternshipDate] IS NOT NULL ORDER BY ModifiedOn)
AND [InternshipDate].[InternshipDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [Apprenticeship]
ON s.caseID = [Apprenticeship].caseID
AND s.modifiedOn = [Apprenticeship].modifiedOn
AND [Apprenticeship].[Apprenticeship] = (SELECT TOP 1 [Apprenticeship] FROM #CEREligibility WHERE caseID = s.caseID AND [Apprenticeship] IS NOT NULL ORDER BY ModifiedOn)
AND [Apprenticeship].[Apprenticeship] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ApprenticeshipDate]
ON s.caseID = [ApprenticeshipDate].caseID
AND s.modifiedOn = [ApprenticeshipDate].modifiedOn
AND [ApprenticeshipDate].[ApprenticeshipDate] = (SELECT TOP 1 [ApprenticeshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ApprenticeshipDate] IS NOT NULL ORDER BY ModifiedOn)
AND [ApprenticeshipDate].[ApprenticeshipDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [Entrepreneurship]
ON s.caseID = [Entrepreneurship].caseID
AND s.modifiedOn = [Entrepreneurship].modifiedOn
AND [Entrepreneurship].[Entrepreneurship] = (SELECT TOP 1 [Entrepreneurship] FROM #CEREligibility WHERE caseID = s.caseID AND [Entrepreneurship] IS NOT NULL ORDER BY ModifiedOn)
AND [Entrepreneurship].[Entrepreneurship] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EntrepreneurshipDate]
ON s.caseID = [EntrepreneurshipDate].caseID
AND s.modifiedOn = [EntrepreneurshipDate].modifiedOn
AND [EntrepreneurshipDate].[EntrepreneurshipDate] = (SELECT TOP 1 [EntrepreneurshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EntrepreneurshipDate] IS NOT NULL ORDER BY ModifiedOn)
AND [EntrepreneurshipDate].[EntrepreneurshipDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EmploymentPrep]
ON s.caseID = [EmploymentPrep].caseID
AND s.modifiedOn = [EmploymentPrep].modifiedOn
AND [EmploymentPrep].[EmploymentPrep] = (SELECT TOP 1 [EmploymentPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrep] IS NOT NULL ORDER BY ModifiedOn)
AND [EmploymentPrep].[EmploymentPrep] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EmploymentPrepDate]
ON s.caseID = [EmploymentPrepDate].caseID
AND s.modifiedOn = [EmploymentPrepDate].modifiedOn
AND [EmploymentPrepDate].[EmploymentPrepDate] = (SELECT TOP 1 [EmploymentPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrepDate] IS NOT NULL ORDER BY ModifiedOn)
AND [EmploymentPrepDate].[EmploymentPrepDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [OTPrep]
ON s.caseID = [OTPrep].caseID
AND s.modifiedOn = [OTPrep].modifiedOn
AND [OTPrep].[OTPrep] = (SELECT TOP 1 [OTPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrep] IS NOT NULL ORDER BY ModifiedOn)
AND [OTPrep].[OTPrep] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [OTPrepDate]
ON s.caseID = [OTPrepDate].caseID
AND s.modifiedOn = [OTPrepDate].modifiedOn
AND [OTPrepDate].[OTPrepDate] = (SELECT TOP 1 [OTPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrepDate] IS NOT NULL ORDER BY ModifiedOn)
AND [OTPrepDate].[OTPrepDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ExitInterview]
ON s.caseID = [ExitInterview].caseID
AND s.modifiedOn = [ExitInterview].modifiedOn
AND [ExitInterview].[ExitInterview] = (SELECT TOP 1 [ExitInterview] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterview] IS NOT NULL ORDER BY ModifiedOn)
AND [ExitInterview].[ExitInterview] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ExitInterviewDate]
ON s.caseID = [ExitInterviewDate].caseID
AND s.modifiedOn = [ExitInterviewDate].modifiedOn
AND [ExitInterviewDate].[ExitInterviewDate] = (SELECT TOP 1 [ExitInterviewDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterviewDate] IS NOT NULL ORDER BY ModifiedOn)
AND [ExitInterviewDate].[ExitInterviewDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CreatedOn]
ON s.caseID = [CreatedOn].caseID
AND s.modifiedOn = [CreatedOn].modifiedOn
AND [CreatedOn].[CreatedOn] = (SELECT TOP 1 [CreatedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedOn] IS NOT NULL ORDER BY ModifiedOn)
AND [CreatedOn].[CreatedOn] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CreatedBy]
ON s.caseID = [CreatedBy].caseID
AND s.modifiedOn = [CreatedBy].modifiedOn
AND [CreatedBy].[CreatedBy] = (SELECT TOP 1 [CreatedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedBy] IS NOT NULL ORDER BY ModifiedOn)
AND [CreatedBy].[CreatedBy] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ModifiedOn]
ON s.caseID = [ModifiedOn].caseID
AND s.modifiedOn = [ModifiedOn].modifiedOn
AND [ModifiedOn].[ModifiedOn] = (SELECT TOP 1 [ModifiedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedOn] IS NOT NULL ORDER BY ModifiedOn)
AND [ModifiedOn].[ModifiedOn] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ModifiedBy]
ON s.caseID = [ModifiedBy].caseID
AND s.modifiedOn = [ModifiedBy].modifiedOn
AND [ModifiedBy].[ModifiedBy] = (SELECT TOP 1 [ModifiedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedBy] IS NOT NULL ORDER BY ModifiedOn)
AND [ModifiedBy].[ModifiedBy] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [BCPermInEligibility]
ON s.caseID = [BCPermInEligibility].caseID
AND s.modifiedOn = [BCPermInEligibility].modifiedOn
AND [BCPermInEligibility].[BCPermInEligibility] = (SELECT TOP 1 [BCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [BCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
AND [BCPermInEligibility].[BCPermInEligibility] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CCPermInEligibility]
ON s.caseID = [CCPermInEligibility].caseID
AND s.modifiedOn = [CCPermInEligibility].modifiedOn
AND [CCPermInEligibility].[CCPermInEligibility] = (SELECT TOP 1 [CCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
AND [CCPermInEligibility].[CCPermInEligibility] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [M2EligibilityDate]
ON s.caseID = [M2EligibilityDate].caseID
AND s.modifiedOn = [M2EligibilityDate].modifiedOn
AND [M2EligibilityDate].[M2EligibilityDate] = (SELECT TOP 1 [M2EligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [M2EligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
AND [M2EligibilityDate].[M2EligibilityDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CDREligibilityDate]
ON s.caseID = [CDREligibilityDate].caseID
AND s.modifiedOn = [CDREligibilityDate].modifiedOn
AND [CDREligibilityDate].[CDREligibilityDate] = (SELECT TOP 1 [CDREligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
AND [CDREligibilityDate].[CDREligibilityDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ExitSeparationCode]
ON s.caseID = [ExitSeparationCode].caseID
AND s.modifiedOn = [ExitSeparationCode].modifiedOn
AND [ExitSeparationCode].[ExitSeparationCode] = (SELECT TOP 1 [ExitSeparationCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationCode] IS NOT NULL ORDER BY ModifiedOn)
AND [ExitSeparationCode].[ExitSeparationCode] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ExitSeparationSubCode]
ON s.caseID = [ExitSeparationSubCode].caseID
AND s.modifiedOn = [ExitSeparationSubCode].modifiedOn
AND [ExitSeparationSubCode].[ExitSeparationSubCode] = (SELECT TOP 1 [ExitSeparationSubCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationSubCode] IS NOT NULL ORDER BY ModifiedOn)
AND [ExitSeparationSubCode].[ExitSeparationSubCode] IS NOT NULL
GROUP BY s.caseID
When I ran this against your test data, It produced a single row for each of the two case ID's.
To keep performance in line, I also created a covering index on the temp table:
CREATE INDEX idx_caseID_ModifiedOn ON #CEREligibility (caseID, modifiedOn) INCLUDE ([CEREligibilityId], [M2Eligibility], [CDREligibility], [M2Comments], [M2CommentsRtf], [CDRComments], [CDRCommentsRtf], [RIAWA], [RIAWADate], [EducationAndTraining], [EducationAndTrainingDate], [Internship], [InternshipDate], [Apprenticeship], [ApprenticeshipDate], [Entrepreneurship], [EntrepreneurshipDate], [EmploymentPrep], [EmploymentPrepDate], [OTPrep], [OTPrepDate], [ExitInterview], [ExitInterviewDate], [CreatedOn], [CreatedBy], [ModifiedBy], [BCPermInEligibility], [CCPermInEligibility], [M2EligibilityDate], [CDREligibilityDate], [ExitSeparationCode], [ExitSeparationSubCode])
Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question. -
i have table dept of deptno d001,d002,d003,d004
i want to list the data like below
deptno
d001,d002,d003,d004 ( in a single row)
is it possible..?
SBased on your database version you can try any one of the following http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
-
Display of data in a single row
Hi
Here is my query:
SELECT
--Element Classification Details:
pec.CLASSIFICATION_ID,
pec.classification_name,
pec1.classification_id "Sub Classification Id",
DECODE(pec1.classification_name,'Other Deductions', 'Other Deductions',
'Others Voluntary Deductions', 'Other Deductions',
'Personal Deductions', 'Personal Deductions',
'Personal Voluntary Deductions', 'Personal Deductions',
'Car Loan Deductions') "Sub Classification",
pec1.parent_classification_id,
scr.sub_classification_rule_id,
--Element Details:
pet.element_name, pet.element_type_id, pet.reporting_name,
DECODE(pet.processing_type, 'R', 'Recurring', 'Nonrecurring') "Processing Type",
pet.EFFECTIVE_START_DATE, pet.EFFECTIVE_END_DATE,
--Run Result Details:
prr.run_result_id,
TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)) "Amount",
piv.NAME "Input Value",
--Assignment Details:
paa.assignment_id,
--Time Period
ptp.START_DATE, ptp.end_date,
ptp.period_name "Payroll Period"
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv,
hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
AND paa.payroll_id != 0
AND paa.pay_basis_id != 0
AND paa.ASSIGNMENT_ID = '560'
I needed to display the amounts as separate columns pertaining to different elements or rather different sub classification of the elements
This is the final expected result for the report:
Employee Personal Deductions PD Amount Other Deductions OD Amt
XYZ Element1 00000.00 Element3 0000.00
Element 2
Car Loan Deductions CLD Amt Total Deductions (Total of all three)
Element4 00000.00 00000000.00
Here Personal Deductions, Other, Car Loan etc. are grouping of elements (sub classifications)
I have used MAX function to display the results as separate columns like this:
SELECT
--Run Result Details:
prr.run_result_id,
MAX(DECODE(pec1.classification_name, 'Personal Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Personal Deductions",
MAX(DECODE(pec1.classification_name, 'Personal Voluntary Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Personal V Deductions",
MAX(DECODE(pec1.classification_name, 'Other Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Other Deductions",
MAX(DECODE(pec1.classification_name, 'Others Voluntary Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Others V Deductions",
MAX(DECODE(pec1.classification_name, 'Car Loan Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Car Loan Deductions"
/*--Assignment Details:
paa.assignment_id,
--Time Period
ptp.START_DATE, ptp.end_date,
ptp.period_name "Payroll Period"*/
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv
/*hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp*/
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
/*AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
--and pet.element_NAME like 'IVTB%'
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE*/
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
--and paa.PRIMARY_FLAG like 'Y%'
/*AND paa.payroll_id != 0
AND paa.pay_basis_id != 0*/
GROUP BY
prr.run_result_id
However, the fact is that my each element_type_id has each run_result_id, which means 1 element has 1 run result id. Thus, I cannot display the data in a single row.
Can someone guide me on this? How can I display the data for an employee as a single row?
Thanks and regards,
AparnaSELECT EMP_ID,
Sum(Decode(DECODE(pec1.classification_name,'Other Deductions', 'Other Deductions','Others Voluntary Deductions', 'Other Deductions'),'Other Deductions',TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Other deduction',
sum(Decode(DECODE(pec1.classification_name,'Personal Deductions', 'Personal Deductions', 'Personal Voluntary Deductions', 'Personal Deductions'),'Personal Deductions'),TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Personal deduction',
sum(DECODE(pec1.classification_name,'Car Loan Deductions',TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Car deduction'
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv,
hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
AND paa.payroll_id != 0
AND paa.pay_basis_id != 0
I hope this may help!
Brijesh -
SQL Update a Single Row Multiple Times Using 2 Data Sets
I'm working in tsql and have an issue where I need to do multiple updates to a single row based on multiple conditions.
By Rank_
If the column is NULL I need it to update no matter what the Rank is.
If the Ranks are the same I need it to update in order of T2_ID.
And I need it to use the last updated output.
I've tried using the update statement below but it only does the first update and the rest are ignored. Here is an example of the data sets i'm working w/ and the Desired results. Thanks in advance!
update a
set Middle = case when a.Rank_> b.Rank_ OR a.Middle IS NULL then ISNULL(b.Middle,a.Middle) end,
LName = case when a.Rank_> b.Rank_ OR a.Lname IS NULL then ISNULL(b.LName,a.LName) end,
Rank_ = case when a.Rank_> b.Rank_ then b.Rank_ end
from #temp1 a
inner join #temp2 b on a.fname = b.fname
where b.T2_ID in (select top 100% T2_ID from #temp2 order by T2_ID asc)The Merge clause actually errors because it attempt to update the same record. I think this CTE statement is the closest I've come but I'm still working through it as I'm not too familiar w/ them. It returns multiple rows which I will have to
insert into a temp table to update since the resulting row I need is the last in the table.
;WITH cteRowNumber
AS(
Select DISTINCT
Row_Number() OVER(PARTITION BY a.LName ORDER BY a.LName ASC, a.Rank_ DESC,b.T2ID ASC) AS RowNumber
,a.FName
,a.LName
,b.LName as xLname
,a.MName
,b.MName AS xMName
,a.Rank_
,b.Rank_ AS xRank
,b.T2ID
FROM #temp1 a
inner join #temp2 b
ON a.fname = b.fname
), cteCursor
AS(
Select a.RowNumber,
a.Fname
,a.LName
,a.xLname
,a.MName
,a.xMName
,a.xRank
,a.T2ID
,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xRank,a.Rank_) else ISNULL(a.Rank_,a.xRank) end AS Alt_Rank_
,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xMName,a.MName) else ISNULL(a.MName,a.xMName) end AS Alt_MName
,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xLName,a.lname) else ISNULL(a.LName,a.xlname) end as Alt_Lname
FROM cteRowNumber a
where a.RowNumber = 1
UNION ALL
Select crt.RowNumber
,crt.FName
,crt.LName
,crt.xLname
,crt.MName
,crt.xMName
,crt.xRank
,crt.T2ID
,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xRank,Prev.Alt_Rank_) else ISNULL(Prev.Alt_Rank_,crt.xRank) end AS Alt_Rank
,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xMName,Prev.Alt_MName) else ISNULL(Prev.Alt_MName,crt.xMName) end AS Alt_MName
,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xLName,Prev.Alt_Lname) else ISNULL(Prev.Alt_Lname,crt.xLName) end as Alt_Lname
FROM cteCursor prev
inner join cteRowNumber crt
on prev.fname = crt.fname and prev.RowNumber + 1 = crt.RowNumber
SELECT cte.*
FROM cteCursor cte -
Multiple clobs in a single row of data
I have several clobs in a single row of data and have created a procedure where I attempt to display the first 4k of each clob.
using a for loop cursor I select all of the clobs in a row at the same time and then I use dbms_lob.read to get the first 4k of data.
For the first lob of each row everything works fine but when I attempt to dbms_lob.read the second one I get an "ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275" and I'm not sure why?
does anyone know of an example where two or more clobs are selected and then converted to 4K varchars?
sample columns for the table:
SPECIALREQUIREMENTSS CLOB
REFERENCERANGE CLOB
ALERTVALUE CLOB
REFERENCELAB VARCHAR2(50 CHAR)
TESTINCLUDES CLOB
LASTUPDATE DATE
sample code (I removed some code for clairity - this produces the same error):
create or replace
procedure test_lobs as
v_lab_blob blob;
v_lobamt binary_integer := 32767;
v_lobpos pls_integer := 1;
v_labrec labman.lab_testingdata%rowtype;
v_buffer varchar2(32767) :='';
v_start_left number;
begin
-- *** housekeeping
dbms_lob.createtemporary(v_labrec.testincludes,TRUE);
dbms_lob.createtemporary(v_labrec.specialrequirementss,TRUE);
Plpdf.init;
Plpdf.NewPage;
Plpdf.SetColor4Drawing(66,66,66);
Plpdf.SetColor4Filling(180,180,180);
v_start_left := Plpdf.GetPageWidth-Plpdf.GetPageRightSpace;
-- *** select the test name for shaded printing
for x in (select indexnumber, test from labman.lab_testingdata where test like 'A%') loop
-- *** select the test data for printing
select * into v_labrec from labman.lab_testingdata where indexnumber = x.indexnumber;
-- *** test includes
if dbms_lob.getlength(v_labrec.testincludes) > 0 or v_labrec.testincludes is not null then
Plpdf.SetPrintFont('Arial','B',8);
Plpdf.LineBreak(.1);
Plpdf.PrintCell(25,5,'Test Includes:',0,0,'R',0,null,0);
Plpdf.SetPrintFont('Arial',null,8);
if dbms_lob.getlength(v_labrec.testincludes) > 32767 then
v_buffer := '*** error - text is greater than 32k ***';
else
v_lobamt := 32767;
v_buffer := '';
dbms_lob.read(v_labrec.testincludes,v_lobamt,v_lobpos,v_buffer);
end if;
Plpdf.SetLeftMargin(Plpdf.GetCurrentX);
Plpdf.PrintFlowingText(5,v_buffer,null,0);
Plpdf.SetLeftMargin(v_start_left);
Plpdf.lineBreak;
end if;
-- *** special requirements
Plpdf.SetPrintFont('Arial','B',8);
Plpdf.LineBreak(.1);
Plpdf.PrintCell(25,5,'Special Requirements:',0,0,'R',0,null,0);
Plpdf.SetPrintFont('Arial',null,8);
if dbms_lob.getlength(v_labrec.specialrequirementss) > 32767 then
v_buffer := '*** error - text is greater than 32k ***';
elsif dbms_lob.getlength(v_labrec.specialrequirementss) = 0 then
v_buffer := '';
else
v_lobamt := 32767;
v_buffer := '';
dbms_lob.read(v_labrec.specialrequirementss,v_lobamt,v_lobpos,v_buffer);
end if;
Plpdf.SetLeftMargin(Plpdf.GetCurrentX);
Plpdf.PrintFlowingText(5,v_buffer,null,0);
Plpdf.SetLeftMargin(v_start_left);
Plpdf.lineBreak;
commit;
end loop;
Plpdf.SendDoc(v_lab_blob);
-- store the PDF document
delete from store_blob;
commit;
INSERT INTO STORE_BLOB (blob_file, created_date)
VALUES (v_lab_blob, SYSDATE);
COMMIT;
end test_lobs;didn't think that checking for a length of zero and null would produce two different results - should have known better.
Thanks for your help!
elsif dbms_lob.getlength(v_labrec.specialrequirementss) = 0
or v_labrec.specialrequirementss is null then -
How to store array of data into a single row of table ,using any of Stmts
HI Friends,
Based on my requirements ,i have retrived a set of data from a XXX.jsp page using a request.getParameter() and stored into single dimenssional array . Now i am paassing that array to JAVA class to store a into some table .
In JSP page users can add text boxes dynamically based on his intrest then those attributes will store in table .it means table attributes are not conatant , it table attributes may change at any time when user adds any textboxs or any fields on JSP page ....thats my module ..
Now i wanted to store all array of data into Table in a single row .......thats is my requirements .
How can we use prepareStatement and Statement to store array of results intoo table row ...on each iteration i wanted to store array of results into table atributes ..It means entire array of results should to into table row at time .....coule any one write sytax ,how we do this...
could any one suggest me stps that i can impliment ......?....please reply ASAPWell ..you code can be works for constant number of attributes in table .oopss here my requirement is table attributes not fixed ,we cant put constant number of place holder(? ) in a statement ,because those are not fixed ,
Let me explain here :
i am doing in that way only. As i mentioned you Table attributes are not constant .It may very if users add any fields dynamically on JSP page .If users have option to add any text box on Jsp page ,then that attribute will store in table as a attribute .
Now i amable fetching the all dyamic form data and stored in a Result Array below ...in this iteration all form result data are from jsp page as suggestion form ,it should stored in table in single row on corrsponding attribtes ......next time when users fills FROM ,then those data i am fetching and storing in a Result Array as below and need to store in corrsponding table attributes in a single row ....
for(int i=0;i<result.length;i++)
System.out.println(result);
pst3=connection.prepareStatement("insert into *emprecord* values(?)");
if(!result[i].equals(""))
System.out.println(result[i]);
pst3.setString(1,result[i]);
pst3.executeUpdate();
Thnks in advance ....let me know the the way we can store dynamic form data into dyanamic table ... -
How to update a single row of data table
How we can update a single row of the data table by clicking the button in the same row.
Thanks in Advance.Hi!
What do You mean 'update'? Get fresh data from DB or change data and commit it in DB?
If commit, try to read here:
http://developers.sun.com/jscreator/learning/tutorials/2/inserts_updates_deletes.html
Thanks,
Roman. -
How to loop through a single row of data?
What I'm trying to do is use a cursor to loop through a clob. When I create my cursor I get the an error telling me that the table does not exist. Which implies that I have an implicit cursor. Is there a way to get around this?
> How to loop through a single row of data?
By not looping as there is only a single row?
> What I'm trying to do is use a cursor to loop through a clob
Processing (looping through) a CLOB has nothing to do with a cursor.
> When I create my cursor I get the an error telling me that the table does
not exist. Which implies that I have an implicit cursor.
Incorrect. It simply means that
a) you do not have permissions to access that table from within the current context
b) it does not exist (e.g. you have misspelled the object name, you have not qualified it properly within the current scope, etc) -
Split single row in multiple rows based on date range
I need sql script that can split single row in multiple rows based on start date and end date column in table.
Thank youI agree to your suggestion of having a dates table permanently in the database. Thats how we also do for most of our projects as well
But in most projects the ownership of table creation etc lies with the client as they will be the DBAs and will be design approval authorities. What I've seen is the fact that though
many of them are in favour of having calendar table they dont generally prefer having a permanent table for numbers in the db. The best that they would agree is for creating a UDF which will have
tally table functionality built into it based on a number range and can be used in cases where we need to multiply records as above.
Wherever we have the freedom of doing design then I would also prefer creating it as a permanent table with required indexes as you suggested.
>> many of them are in favour of having calendar table they dont generally prefer having a permanent table
Those people do not understand about database and are not DBAs :-)
It is our job to tell them what is right or wrong.
** This is a real story! I had a client several years back, who was the CEO of a software company.
He use the query:
select * from table_name
In order to get the last ID!
The table_name was actually a view that took data from several tables, and the main table that he wanted to get the ID included several string columns, with lot of data!
he actually pulled all this data to the application, just to get the lat ID in a specific table!
It is our job as Consultants or DBAs to fix's his misunderstanding :-)
Ronen Ariely
[Personal Site] [Blog] [Facebook] -
Alternative way to fetch the data into single row.
we have a query
SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME='XXX';
This query will return the data in multiple rows.
May know the alternative way to retrieve all the multiple rows in **single row with each row as a seperate column**.Why specifically an array - and do you want the SQL projection as an array, or collect the SQL projection into an array?
E.g.
SQL> create or replace type TStrings is table of varchar2(4000);
2 /
Type created.
SQL> --// SQL projection casted into an array
SQL> select
2 cast(
3 MultiSet(
4 select column_name from all_tab_columns where table_name = 'KU$_DATAPUMP_MASTER_11_2' and owner = 'SYS'
5 )
6 as TStrings
7 ) as COLUMN_ARRAY
8 from dual
9 /
COLUMN_ARRAY
TSTRINGS('REMOTE_LINK', 'VERSION', 'JOB_VERSION', 'DB_VERSION', 'TIMEZONE', 'STATE', 'PHASE', 'GUID', 'START_TIME', 'BLOCK_SIZE', 'METADATA_BUFFER_SIZE', 'DATA_BUFFER_SIZE', 'DEGREE', 'PLATFORM', 'ABO
RT_STEP', 'INSTANCE', 'CLUSTER_OK', 'SERVICE_NAME', 'OBJECT_INT_OID', 'PROCESS_ORDER', 'DUPLICATE', 'DUMP_FILEID', 'DUMP_POSITION', 'DUMP_LENGTH', 'DUMP_ORIG_LENGTH', 'DUMP_ALLOCATION', 'COMPLETED_ROW
S', 'ERROR_COUNT', 'ELAPSED_TIME', 'OBJECT_TYPE_PATH', 'OBJECT_PATH_SEQNO', 'OBJECT_TYPE', 'IN_PROGRESS', 'OBJECT_NAME', 'OBJECT_LONG_NAME', 'OBJECT_SCHEMA', 'ORIGINAL_OBJECT_SCHEMA', 'ORIGINAL_OBJECT
_NAME', 'PARTITION_NAME', 'SUBPARTITION_NAME', 'DATAOBJ_NUM', 'FLAGS', 'PROPERTY', 'TRIGFLAG', 'CREATION_LEVEL', 'COMPLETION_TIME', 'OBJECT_TABLESPACE', 'SIZE_ESTIMATE', 'OBJECT_ROW', 'PROCESSING_STAT
E', 'PROCESSING_STATUS', 'BASE_PROCESS_ORDER', 'BASE_OBJECT_TYPE', 'BASE_OBJECT_NAME', 'BASE_OBJECT_SCHEMA', 'ANCESTOR_PROCESS_ORDER', 'DOMAIN_PROCESS_ORDER', 'PARALLELIZATION', 'UNLOAD_METHOD', 'LOAD
_METHOD', 'GRANULES', 'SCN', 'GRANTOR', 'XML_CLOB', 'PARENT_PROCESS_ORDER', 'NAME', 'VALUE_T', 'VALUE_N', 'IS_DEFAULT', 'FILE_TYPE', 'USER_DIRECTORY', 'USER_FILE_NAME', 'FILE_NAME', 'EXTEND_SIZE', 'FI
LE_MAX_SIZE', 'PROCESS_NAME', 'LAST_UPDATE', 'WORK_ITEM', 'OBJECT_NUMBER', 'COMPLETED_BYTES', 'TOTAL_BYTES', 'METADATA_IO', 'DATA_IO', 'CUMULATIVE_TIME', 'PACKET_NUMBER', 'INSTANCE_ID', 'OLD_VALUE', '
SEED', 'LAST_FILE', 'USER_NAME', 'OPERATION', 'JOB_MODE', 'QUEUE_TABNUM', 'CONTROL_QUEUE', 'STATUS_QUEUE')
SQL> --// collecting the SQL projection as an array
SQL> declare
2 colArray TStrings;
3 begin
4 select
5 column_name bulk collect into colArray
6 from all_tab_columns
7 where table_name = 'KU$_DATAPUMP_MASTER_11_2'
8 and owner = 'SYS';
9
10 --// process array
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> -
Single row of XML data missing
OK, much strangeness here.
I have an mx:DataGrid taking its data from an array
collection thusly:
logSheetData = logs.lastResult.logsheet.data as
ArrayCollection;
The XML is being generated perfectly by a php page.
If the xml consists of 2 or more nodes (i.e. the mysql_query
returned 2 or more rows of data from the database) then the grid
populates properly and everyone is happy. However, if the query
returns only a single row of data, the grid is blank.
I've checked the php and the contents of the database - if
there's only a single row of data to come back, one row's worth of
XML is returned.
This has been driving me mad all morning! Help!
-Update-
I have patched the problem by adding in an empty node to the
xml structure if only 1 row of data is returned - this seems to
fool the grid and causes it to display properly. Buy why!Corvette Captain wrote:
In an interactive report, is it possible to display the data from one database row over two or more displayed rows on a page?Yes. Create the required structure using the Detail View properties.
Users can switch between views using the view controls. You can display the report in Detail View by default via a Dynamic Action: +{thread:id=2187972}+
Maybe you are looking for
-
Wow.Apple and I both thought computer was DOA!! (Boot Camp Crash)
Ok. Here's what happened. I still can't believe no one at Apple thought of a solution for me...read on. I was attempting to install Windows XP using BootCamp Assistant when it came to the page directing me to choose which hard drive or partition to i
-
The Airplay menu shows an Airport Express that is no longer in use.
The Airplay menu in iTunes shows an old Airport Express that is no longer in use. How do I remove it from the list?
-
My phone totally died. How do I get it to respond?
My Iphone is totally dead. how do I restart it??
-
SOAP--PI--ABAP Proxy-how to call this scenarion from third-party PeopleSoft
My scenario is: Third-party Peoplesoft sending an Asynchronous XML message to PI through SOAP Adapter which will then be processed by ABAP proxy server. I have everything in place (SDL,IR,ID & ABAP Proxy). I have created a SOAP tool that uses URL (ht
-
I need to generate a SWF file that will be converted into EXE and recorded a CD. When I run the EXE file on the CD takes it to appear in full screen. I can not do this in InDesign. The file is generated, but when I run is converted not appear in full