Need Logic in sql
Declare @table table (EMPIID int, NAME VARCHAR(10),Updatedate datetime)
INSERT into @table values(111,'Muthu','02/13/2014')
INSERT into @table values(222,'Mari','02/14/2014')
INSERT into @table values(222,'Raja','02/13/2014')
INSERT into @table values(222,'Muthu','02/14/2014')
INSERT into @table values(333,null,null)
INSERT into @table values(444,'Rahul','02/02/2014')
Select * from @table
I need a output from above table with below logic.
1.For the Emp name that are tied to more than one empid then don’t use these empname for any empids, need to display with some other dumppy name with emp id.
here name muthu belongs to empid 222 so that i need an output for this situation
111 marimuthu '02/13/2014' -- no need to display name muthu belongs to 222.
2) For rest of the names pick the one to the empid if only one name found; otherwise pick the Names with greatest updateDate.
So my final output for above table records should be comes like this
Empid
Name
updateDate
1111
marimuthu
null
2222
muthu
02/14/2014
3333
Muhtu00003333(dumppy)
null
4444
Rahul
02/02/2014
Should it be 111,'Muthu','02/13/2014' rather than ?
1111
marimuthu
null
Declare @table table (EMPIID int, NAME VARCHAR(10),Updatedate datetime)
INSERT into @table values(111,'Muthu','02/13/2014')
INSERT into @table values(222,'Mari','02/14/2014')
INSERT into @table values(222,'Raja','02/13/2014')
INSERT into @table values(222,'Muthu','02/14/2014')
INSERT into @table values(333,null,null)
INSERT into @table values(444,'Rahul','02/02/2014')
select * from
Select empiid,coalesce(name,'dummy') name,updatedate,row_number() over (partition by empiid order by updatedate desc) rn
from @table
) as der where rn=1
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
Do I need Logic Pro 8.0.1 Update, and if so, how do I get it now?
Do I need Logic Pro 8.0.1 Update, and if so, how do I get it now?
Tuesday, 2008-07-29
Due to prolonged illness, I purchased the Logic Studio Upgrade version (I already had Logic Pro 7.2.3, with dongle) only last week. Logic Studio Upgrade version initially installs Logic Pro version 8.0.0. I then dutifully set out to download both the Logic Pro 8.0.1 Update and the Logic Pro 8.0.2 Update.
As of this week, all attempts and maneuvers to simply get the Logic Pro 8.0.1 Update have failed. I cannot even find it, let alone download it!
Yes, I've tried the relabeling juggling act to fool Software Update into eventually listing and providing both the Logic Pro 8.0.1 Update and the Logic Pro 8.0.2 Update—but no luck, not any longer. These moves may have worked up until relatively recently, but they do not work now, at least as of this week.
All searching of Apple's site(s) and Support pages results in nada—Apple itself no longer lists any such file/dmg/download/update anywhere! All previous links are either dead or just dump one back on to the Logic Pro 8.0.2 Update page.
(In my many searches, I noted what seemed to me to be a majority of opinion that the Logic Pro 8.0.1 Update was a dog, especially in Mac OS X Leopard 10.5.2 or 10.5.3. Many users reported crashes, panics, and.or freezes. Is this why Apple has pulled the update and rendered it extinct?)
I Googled, I Asked Why, I Cuiled—but no Logic Pro 8.0.1 Update, except as that which lurked in the murky warez waters. Still, frustrated as I was, I did even try all such I could find . . . but no third party-hosted update worked at all.
I am concerned because in all my previous experience with Apple and its applications, ample information is made readily available about the contents of any update and an explanation of its relationship to previous updates. By this latter I mean: Apple indicates that update "x" incorporates the previous updates "u" and "v"; therefore one can proceed safely to install update "x" even if one missed updates "u" and "v" or for whatever reason did not install them.
So . . . do I need Logic Pro 8.0.1 Update, if I am then going to further update with the Logic Pro 8.0.2 Update? Does Logic Pro 8.0.2 Update incorporate the changes made in Logic Pro 8.0.1 Update? Will I be missing (critically?) something(s) in Logic Pro 8.0.1 Update if I in fact do not ever get it or install it? And how would I know? Apple has not only removed the update and all traces of it, but Apple has also removed all information about Logic Pro 8.0.1 Update—it is now literally as if it never existed.
So what's a po' boy to do? Logic Pro 8.0.1 Update cannot now be found on VersionTracker or MacUpdate or anywhere else. To date, no user group or organization or educational institution or program or audio-related company posted it or archived it.
Where/how can I get a copy of the Logic Pro 8.0.1 Update?
If I can't, what do I do?
If I can't, what do I miss?
And where is Apple's support for Logic Studio/Logic Pro in all of this?
Earnestly hoping,
j.Rodger,
Thank you for your gracious welcome . . .
and thank you for your swift response . . .
and thank you for your information (and encouragement!).
Yes, I read that too, but searched in vain for the specifity of, say, your direction:
"Go ahead and update to 8.0.2, as it contains the 8.0.1 update."
So I shall!
Again, many thanks. -
Need logic for calculate the balance quantity in open sales order
hi all
i need logic to calcuclate the balance quantity in open sales order ,
where i am using VBAK header and VBAP item , and VBFA for document flow tables
i need to have the balance quantity , for the open sales order
especially taking with respect to VBFA-VBTYP_N = M for invoice creation and N for canellation
any one please help methank you but i am clear abt it
will you please anyother way to calucaluate the logic ,
and i need to populate in bukets also for the terms of 5 years
Edited by: sridhar loganathan on Nov 25, 2008 6:43 AM -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Hello,
I need Oracle Payroll SQL Query with result:
First_name, Last_name, Payment_amount, Pay_date, Payroll_Frequency, Employement_status
Any Help would be greatful appreciatedYou will need the following tales.
per_all_people_f, per_all_assignments_f,pay_run_results,pay_run_result_values
Query would e something like :
select papf.first_name,
papf.last_name,
prrv.*
From apps.per_all_people_f papf
apps.per_all_assignments_f paaf
apps.pay_run_results prr,
apps.pay_run_result_values prrv
Where papf.person_id = paaf.person_id
and papf.business_group_id = paaf.business_group_id
and papf.current_employee_flag = 'Y'
and paaf.primary_flag ='Y'
and paaf.assignment_type = 'E'
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
and prr.assignment_id = paaf.assignment_id -
Want to practice SQL queries, do I need to download SQL editor
Hi All,
I have a doubt..
I want to practice SQL queries. for this, do I need to download SQL editor and Intall or If I download any Oracle version, does it will have SQL editor? please anyone answer my question.I'm not sure how is it related to Peoplesoft, but if you installed an Oracle client on your client machine, then you have SQL*Plus or SQL Developer.
Nicolas. -
Need to install SQL*Net?
I am being told that I need something called SQL*Net to get a front end working to access a remote (like 1/2 way around the world) database. I do have the most recent Oracle client tools installed and it seems like it has the necessary networking configuration tools. However, my contact in Denmark is saying to get SQL*Net, the client tools won't cut it and I need to download a full 9i database. Is there any reference out there stating what I'll need and how I configure it?
Generally Oracle client software is installed on Windows, if it is your case these books can be very useful.
Client Installation Guide for 32-Bit Windows Contents / Search / Index / PDF
Client Release Notes for 32-Bit Windows Contents / Search / / PDF
http://otn.oracle.com/pls/db92/db92.docindex?remark=homepage
Joel P�rez -
Prob in using rank in pl/sql ,need logic same of rank function in any way
I have a query as of the following <br>
<br>
SELECT sr_no,cod_acct_no,dat_arrears_due,amt_arrear_due<br>
FROM ( select cod_acct_no,dat_arrears_due,sum(amt_arrears_due) <br>amt_arrear_due,rank() over (partition by cod_acct_no order by <br>dat_arrears_due asc) sr_no<br>
from arrears_table <br>
where amt_arrears_due > 0<br>
and dat_arrears_due <= to_date('31/10/2006','dd/mm/yyyy')<br>
and COD_ARREAR_TYPE = 'C'<br>
group by cod_acct_no,dat_arrears_due<br>
) Z <br>
WHERE z.sr_no <=5 <br>
<br>
I have to use this in a cursor in pl/sql but because i have rank analytic function <br>
I am facing a compilation error ORA-06550: error <br>
<br>
Can you give me a logic which gives same output as of above <br>
<br>
Regards<br>
vamsi krishna<br>
<br>
<br>[1]: (Error): ORA-06550: line 5, column 28: PLS-00103: Encountered the <br>symbol "(" when expecting one of the following: , from <br>
<br>
My oracle version is <br>
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production<br>
PL/SQL Release 8.1.6.0.0 - Production<br>
CORE 8.1.6.0.0 Production<br>
TNS for 32-bit Windows: Version 8.1.6.0.0 - Production<br>
NLSRTL Version 3.4.1.0.0 - Production<br>
<br>I think it is comming for rank function it self <br>
<br> will this version support analytic (rank) function's in pl/sql cursors<br>
Regards<br>
vamsi krishna<br> -
I get a monthly data feed in excel with pcpid and memberid information.I'm supposed to get member detail information for all the members associated only with the pcpid in the spreadsheet
How do i write a query so that i associate a memberid only with the pcpid given in the spreadsheet
The problem iam having is when i write a query to bring the member information by providing pcpid in list , i get multiple records for a member as the member might earlier be associated with another PCPid
Data From Excel
Member No PCP ID
101 A
102 B
103 C
104 D
When i insert these values in to the query to get remaining member Details below is how the data looks
Member No PCP ID
101 A
101 B
101 D
102 A
102 B
103 A
103 C
104 B
104 D
Please Advice.
thanks.SQL and PL/SQL FAQ
I have no idea what data is in the DB & no idea what the result set should be or why? -
Need advise on SQL,plsql developer career and future
Hi all,
I need all your advise in making an important decisions of my career path.I work in the IT field and have about total 4-5 years of work experience involving development and testing in a product based organization.
Presently-i have got chance since last 4-5 months to work with writing PLSQL code,SQL etc on a part basis. I am very much interested to continue my career path as a PLSQL developer.
But, unfortunately -in the total of my work experience-in the past 2-3 years-i worked with a internally developed DB query language(similar to SQL) and then from last few months with plsql. But this chance to work with PLSQL has been for less time and limited scope after which i will have to work on something different.
Ii want to fully take on my career in SQL,PLSQL as Database Developer.
Please advise me if my thinking seems logical and good and if I could do it. I have planned on applying for relevant SQL,PLSQL profile jobs.
Now, My serious worry and concern is I feel that since i have worked very less with PLSQL-so am low in confidence that I feel i wont be able to answer ,or tell or not knowledgeable enough to be able to clear the technical interviews for SQL,plsql development profile which would need at least some years of experience.
I have started studying and practsing PLSQL,sql by myself for from internet. So, can you all please advise me on how could i prepare myself for hard core technical interviews of SQL,PLSQL knowledge for about 2-3 years expertise.
I know its not much possible to be competent so much in the subject by just studying and practicing.Its easy as saying to study and get it by myself-but i want to try and will put my best for it.
Please help me with your inputs,all interview questions,hard ones-suggestions,links,any study materials, real time problems which i can try solving of SQL, PLSQL development.
Thanks AllHi,
A very good starting point is (in my opinion): [Steven Feuerstein PL/SQL Obsession|http://www.toadworld.com/Knowledge/DatabaseKnowledge/StevenFeuersteinsPLSQLObsession/tabid/153/Default.aspx]. Also the official site [PL/SQL Technology Center|http://www.oracle.com/technology/tech/pl_sql/index.html]
Regards, -
Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field
Hello,
I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
Table structures are mentioned below:
OP:
Name Null Type
OP_NBR NOT NULL NUMBER(4) (Primary Key)
OP_DESC VARCHAR2(50)
OP_PAYLOD_XML CLOB
GM:
Name Null Type
GM_NBR NOT NULL NUMBER(4) (Primary Key)
GM_DESC VARCHAR2(40)
OP_NBR NOT NULL NUMBER(4) (Foreign Key)
GM_PAYLOD_XML CLOB
DM:
Name Null Type
DM_NBR NOT NULL NUMBER(4) (Primary Key)
DM_DESC VARCHAR2(40)
GM_NBR NOT NULL NUMBER(4) (Foreign Key)
DM_PAYLOD_XML CLOB
DE:
Name Null Type
DE_NBR NOT NULL NUMBER(4) (Primary Key)
DE_DESC NOT NULL VARCHAR2(40)
DM_NBR NOT NULL NUMBER(4) (Foreign Key)
DE_PAYLOD_XML CLOB
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
FROM
DE g, DM h, GM i, OP j
WHERE
h.dm_nbr = g.dm_nbr(+) and
i.gm_nbr = h.gm_nbr(+) and
j.op_nbr = i.op_nbr(+)
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
Current O/P:
<resultSet>
<Record1>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<DM_PAYLOD_XML1>
<DE_PAYLOD_XML1>
</Record1>
<Record2>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML2>
<DM_PAYLOD_XML2>
<DE_PAYLOD_XML2>
</Record2>
<RecordN>
<OP_PAYLOD_XMLN>
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XMLN>
</RecordN>
</resultSet>
Now i want to change my SQL query so that i get following output structure:
<resultSet>
<Record>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<GM_PAYLOD_XML2> .......
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XML1>
<DM_PAYLOD_XML2> .......
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XML1>
<DE_PAYLOD_XML2> .......
<DE_PAYLOD_XMLN>
</Record>
<Record>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML1'>
<GM_PAYLOD_XML2'> .......
<GM_PAYLOD_XMLN'>
<DM_PAYLOD_XML1'>
<DM_PAYLOD_XML2'> .......
<DM_PAYLOD_XMLN'>
<DE_PAYLOD_XML1'>
<DE_PAYLOD_XML2'> .......
<DE_PAYLOD_XMLN'>
</Record>
<resultSet>
Appreciate your help in this regard!Hi,
A few questions :
How's your first query supposed to give you an XML output like you show ?
Is there something you're not telling us?
What's the content of, for example, <OP_PAYLOD_XML1> ?
I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
What's the db version BTW? -
Help Needed in Dynamic Sql or alternate to Dynamic Sql
Hi Am working in sqlserver 2008 R2 and here is my Table structure and SPC
;create table SalaryReport(IdSalary int primary key identity(1,1),
IDMainCompany int,IDSubCompany int,Salary money,Incentive int,NoofEmployees int, SalaryDate datetime, Creditscore int );
insert into SalaryReport (IDMainCompany,IDSubCompany,Salary,Incentive,NoofEmployees,SalaryDate,Creditscore)
( Select 100 as IDMainCompany , 1000 as IDSubCompany ,200000 AS Salary, 20000 as Incentive, 500 as NoofEmployees,
'2014-01-01' as SalaryDate, 60 as Creditscore union all
Select 100 as IDMainCompany , 1001 as IDSubCompany ,300000 AS Salary, 40000 as Incentive, 600 as NoofEmployees,
'2014-01-01' as SalaryDate , 70 as Creditscore union all
Select 100 as IDMainCompany , 1002 as IDSubCompany ,400000 AS Salary, 40000 as Incentive, 1500 as NoofEmployees,
'2014-01-01' as SalaryDate , 45 as Creditscore union all
Select 101 as IDMainCompany , 1003 as IDSubCompany ,30000 AS Salary, 2000 as Incentive, 100 as NoofEmployees,
'2014-01-01' as SalaryDate, 60 as Creditscore union all
Select 102 as IDMainCompany , 1004 as IDSubCompany ,450000 AS Salary, 25000 as Incentive, 700 as NoofEmployees,
'2014-01-01' as SalaryDate, 30 as Creditscore)
Sample Test Script:
DECLARE @IDMainCompany int = 100;
DECLARE @Process_Date datetime = '2014-01-01';
declare @Query nvarchar(max);
SELECT
CAST(SR.IDMainCompany AS VARCHAR(12)) AS IDMainCompany
,CAST(SR.IDSubCompany AS VARCHAR(12)) AS IDSubCompany
,CAST(SR.Salary AS VARCHAR(12)) AS Salary
,CAST(SR.Incentive AS VARCHAR(12)) AS Incentive
,CAST(SR.NoofEmployees AS VARCHAR(12)) AS NoofEmployees
,CAST(SR.SalaryDate AS VARCHAR(15)) AS SalaryDate
,CAST((SR.Creditscore) AS VARCHAR(15)) AS average
FROM SalaryReport SR
WHERE SR.IDMainCompany = @IDMainCompany
AND DATEPART(MM, SR.SalaryDate) = DATEPART(MM, @Process_Date)
UNION ALL
SELECT
'' AS IDMainCompany
,'' AS IDSubCompany
,'Total: ' + CAST(SUM(SR.Salary) AS VARCHAR(12)) AS Salary
,'Total: ' + CAST(SUM(SR.Incentive) AS VARCHAR(12)) AS Incentive
,'Total: ' + CAST(SUM(SR.NoofEmployees) AS VARCHAR(12)) AS NoofEmployees
,'' AS SalaryDate
,'Total: ' +CAST(avg(SR.Creditscore) AS VARCHAR(12)) AS Totalaverage
FROM SalaryReport SR
WHERE SR.IDMainCompany = @IDMainCompany
AND DATEPART(MM, SR.SalaryDate) = DATEPART(MM, @Process_Date)
group by IDMainCompany, DATEPART(MM, SalaryDate)
the sample data i posted is having less columns. actually i have 20 columns in the select list. Also the parameters to the where condition i gave two i.e IDMainCompany, SalaryDate. I will also need to use IDSubCompany for some case. My skeleton will be
Create Procedure Test(@IDMainCompany int, @IDSubCompany int = null, @SalaryDate datetime)
as
BEGIN
IF(@IDMainCompany is not null && @IDMainCompany > 0 && @SalaryDate is not null && @SalaryDate <> ' ' &&
@IDSubCompany is null)
BEGIN
--The logic what discussed on previous posts will falls here with @IDMainCompany, @SalaryDate as parameter to the where condition
END
IF(@IDMainCompany is not null && @IDMainCompany > 0 && @SalaryDate is not null && @SalaryDate <> ' ' &&
@IDSubCompany is null && @IDSubCompany > 0 )
BEGIN
--The logic what discussed on previous posts will falls here with @IDMainCompany, @SalaryDate,@IDSubCompany as parameter to the where condition
END
END
As said i need to include 20 columns in the select list and as union all used on the previous sample there are 20 columns on the first query and 20 columns on the second query after the union all. The SPC will become big. If i repeat this for second if condition,
it will be too big. How can i reduce this writing more lines.
I am aware of the concept dynamic sql. Is there any other way to do this? or if dynamic sql is the only option, can anyone help me rewriting this select statements as dynamic sql
Could anyone please assist me
loving dotnet>>
thanks for your reply and yes, i am invoking this from my asp.net application using C# language. Would you like to share something?
<<
Yes,
You can use client side dynamic sql. I'm not talking about concatenating strings. I'm talking about using Runtime Text Tamplates (preprocesed templates in Visual Studio 2010).
Add a new "Runtime Text Template" item to your VS project. Be "MyReportTemplate.tt" the file name of the runtime text template. The content of this file should be something like the following:
<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
SELECT
-- part of your query goes here
-- the interesting part come next
FROM
SalaryReport SR
WHERE
SR.IDMainCompany = @IDMainCompany
<# if (IDSubCompany.HasValue && IDSubCompany.Value > 0) { #>
AND SR.IDSubCompany = @IDSubCompany
<# } #>
AND
DATEPART(MM, SR.SalaryDate) = DATEPART(MM, @Process_Date)
GROUP BY
IDMainCompany, DATEPART(MM, SalaryDate)
Add a new c# code file named MyReportTemplate.partial.cs closed to MyReportTemplate.tt with the following code:
public partial class MyReportTemplate
public int? IDSubCompany { get; set; }
Then, to execute the query you can write a code similar to the following:
public DataTable ExecuteReport(int mainCompanyId, int? subCompanyId, DateTime processDate )
using (var cn = CreateConnection())
using (var cmd = new SqlCommand())
using (var adapter = new SqlDataAdapter(cmd))
cmd.Connection = cn;
var template = new MyReportTemplate
IDSubCompany = subCompanyId
cmd.CommandText = template.TransformText();
cmd.Parameters.AddWithValue("@IDSubCompany", subCompanyId == null ? (object) DBNull.Value : subCompanyId.Value);
cmd.Parameters.AddWithValue("@IDMainCompany", mainCompanyId);
cmd.Parameters.AddWithValue("@Process_Date", processDate);
var table = new DataTable();
adapter.Fill(table);
return table;
EntityLite: A Lightweight, Database First, Micro ORM -
Logical standby: SQL Apply too slow
Hi all,
I have a question regarding SQL Apply performance in logical standby. There are two kind of operations that are remarkably slow when applying them on logical standby. These are "truncate table" and "delete from table" operations.
When logical standby pick up one of mentioned statements from logs one of appliers start working whereas rest others are waiting. It looks like standby hang and very slow sql apply is moving on gradually and finally when operation completes standby is behind primary for 4 or 5 or even 8 hours.
What can be done in this regard to speed up sql apply and alleviate this situation?
Best Regards,
AlexAre you absolutely sure that the truncate is the problem (and deletes). How did you check it?
You can use LogMiner to check what are most of the commands in the log currently applied. I use this:
BEGIN
sys.DBMS_LOGMNR.ADD_LOGFILE( LOGFILENAME => '/home/oracle/arc_43547_1_595785865.arc', OPTIONS => sys.DBMS_LOGMNR.ADDFILE);
END;
BEGIN
sys.DBMS_LOGMNR.START_LOGMNR( OPTIONS => sys.DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
END;
SELECT seg_owner,seg_name,table_name,operation,COUNT(1) FROM V$LOGMNR_CONTENTS
GROUP BY seg_owner,seg_name,table_name,operation
ORDER BY COUNT(1) DESC
BEGIN
sys.DBMS_LOGMNR.END_LOGMNR();
END;
Most of the times in our cases when SQL Apply is slow is because of high activity on particular object. This can be detected by high number of DMLs for that object using LogMiner. If this object is not needed on the logical standby you can skip it and thus SQL Apply will be faster because it will not apply changes for this particular one. If it's needed and this is not a regular rate, then you can skip it temporarily, turn on SQL Apply , after problematic logs are applied, turn off SQL Apply, instantiate the object and unskip it, turn on sql apply again.
Another thing that can drastically slowdown SQL Apply is the size of memory available for SQL Apply(Alert log shows that max is ~4.5GB or something like this, I'm not sure )
You can increase it with something like this:
ALTER DATABASE STOP LOGICAL STANDBY APPLY;
BEGIN
DBMS_LOGSTDBY.APPLY_SET('MAX_SGA', 3000); -- set to 3000 MB
END;
ALTER DATABASE START LOGICAL STANDBY APPLY;
You have to increase it if the following reports:
SELECT NAME, VALUE FROM V$LOGSTDBY_STATS
WHERE NAME LIKE '%page%' OR
NAME LIKE '%uptime%' or name like '%idle%';
that 'bytes paged out' increases if run every few seconds during slow SQL Apply.
I hope that it's something that can be fixed using the above info. If no, please comment and share your investigations.
Thanks -
Dynamic WHERE clause logic in SQL based on ITEM value
Hi,
I have a report based on following SQL query.
select dept_no,
dept_name,
dept_loc
from dept
where dept_loc = :P1_DEPT_LOC
// If P1_DEPT_LOC is not null, I want the WHERE clause and IF P1_DEPT_LOC is null, then I don't need the WHERE clause.
// how can I build this logic in same SQLThanks,
Deepak
Edited by: Deepak_J on Mar 11, 2010 4:37 PMDeepak,
If p1_dept_loc were a LOV, this would work.
SELECT deptno,
dname,
loc
FROM dept
WHERE ( :p1_dept_loc = '%null%' OR loc LIKE '%' || :p1_dept_loc || '%' )
Jeff -
Script Logic choice SQL or MDX in NW release?
Hi experts,
I have encountered some opposite arguments in forum. Please can you clarify NW release script logic choice should be as MS release?
In [Script Logic BPC MS (SQL) vs. NW (ABAP); Tim Klem states
- "Write the logic using BPC SQL script logic syntax (not MDX) for performance reasons" but this opinion based on MS version. How about NW release is it really smarter to select SQL Script rather than MDX.
There is another statement in [Re: BPC 7 NW; Deppak mentions that:
- "In BPC 5.1 the script formula approach suggests to use SQL based logic instead of MDX.
Whereas in Teched,08, I learnt that MDX & ABAP (using BADIs) would be used for it. Thats why I am slightly confused...."
But second statement is far beyond NW relase date and I am sure this is not true but I would like you to confirm that.
If you were a project responsible and want that all scripts will be held in one language, what would you choose??
Thanks in advance,
ergin ozturkHi Ergin,
I can understand your approach not to use ABAP hence you miss the skills witin your project team.
However, you (or you client) has chosen the NetWeaver version for whatever reason. I'm sure a thorough decisions process has lead to this decision. In choosing the NetWeaver version with SAP BI you will sooner or later come to the point that you will have to use ABAP if you like it or not. Especially when you start using further capabilities within NetWeaver and the BI solutions. So from my point of view ABAP knowledge is an essential skill you need in a project based on SAP NetWeaver anyway.
Additionally I heared some statements that MDX is causing some performance issues on the NetWeaver version. This may have been fixed in the meantime with some SPs.
As the SQL within the NetWeaver verison does not have the full functionality than it has in MS Version SQL is not an option for me.
I do also not see the cost impact hence someone need to do the support anyway. In case of MDX you need an MDX developer, in case of ABAP and ABAP developer. Or a technical BPC consultant able to do the development (which I would recommend you should have in your project team anyway).
So coming back to your original question, I would recommend to do as much as possible using ABAP BADIs.
Cheers,
Steffen
Maybe you are looking for
-
Hi there-- I have a fully stock-configured (no mods, no hard drive tweaks, etc.) Macbook Pro (17-inch, mid 2010, i5 model). It's only 3 months old. Running 10.6.4, everything updated and NO peripherals connected... Anyhow, I was working at Starbucks
-
Is it possible to take 2 PO print outs for same vendor w different currency
Hi all.. I have Created vendor In INR currency. client want to take 2 same PO print outs in 2 languages say one PO print in INR currency and one more in USD currency with out changing Vendor currency in vendor master.. Is possible in SAP?? Plz give u
-
Hi, I'm sure this was covered somewhere but I can't seem to find it, I'm new here So my HD crashed and I just got everything back up and running but I didn't have a few things backed up like some movies and old purchased apps that I no longer had on
-
Kaffeine-1.0pre1 : could not open media source
Hi, The new kaffeine using Qt4 has an issue when trying to play a video file or DVB-T: "Could not open media source" DVB-T channel scanning works perfectly. I guess there is a problem with the video output. Am I missing some dependency ? Thanks.
-
I ordered my iPad on May 24, and received it today, June 7. It did indeed offer me the option to choose the $29.99 unlimited plan, which I promptly did! Evidently, the info posted on the Apple Store site about ORDERING before June 6 was a fact. I was