Speeding up a query on a concatenated field.
Hi,
I have a view with a concatenated field that basically comes down on this:
ALTER VIEW [dbo].[_FO_QP_Items_4_0] AS
SELECT
Col A ,Col B --etc
,CONVERT(nvarchar(36), sysguid) +'|'+crdnr AS [LevCode]
FROM table A
As you see I am concatenating 2 fields together to get a unique [LevCode] (concatenating Itemcode + Supplier code)
If I query that view like this, it runs rather slow on a 500.000+ rows table:
SELECT *
FROM [dbo].[_FO_QP_Items_4_0]
WHERE [LevCode] = 'DF007704-38EF-4389-8544-E70CC32404D5| 60102'
ORDER BY Col A
Unfortunately I am not able to add an extra column to the table and concatenate the fields there.
Is there a way to speed up the query (or view).
Thanks for helping me out here.
Index view has high overhead. It has to be really justified.
BOL: "Indexed views work best when the underlying data is infrequently updated. The maintenance of an indexed view can be greater than the cost of maintaining a table index. If the underlying data is updated frequently, the cost of maintaining the indexed
view data may outweigh the performance benefits of using the indexed view. If the underlying data is updated periodically in batches but treated primarily as read-only between updates, consider dropping any indexed views before updating, and rebuilding them
afterward. Doing this may improve performance of the updates."
Reference:
https://technet.microsoft.com/en-us/library/ms187864%28v=sql.105%29.aspx?f=255&MSPPError=-2147217396
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014
Similar Messages
-
Cast 3 Concatenated Fields as Date
Hi,
I have the following requirement. On the contact page there is a drop down field named Starting month of months (Jan to Dec). On the report i need to show Starting Date column, which is a concatenated field of 01 as date, Value in the Starting month field and current year.
For Ex: If user select Feb , on the report in Starting Date column it should display 01-Feb-2011. This can be achieved using combination of concat functions. But i also need another column to show if starting date is passed or not based on Starting Date coulumn and current date. To do that i need to cast the concatenated field (i.e Starting month) to Date.
But when i try to cast starting date as DATE, i get a error message. The sample cast function i have used is "CAST(REPLACE(CAST(YEAR(CURRENT_DATE) AS CHARACTER) ||'-'|| CASE WHEN Contact.PICK_10='Jan' THEN '01' ELSE Contact.PICK_10 END || '-' || '01', ' ', '') AS DATE)" .
Does anyone knows how to cast strings as Date? Any workarounds on this issue is appreciated.
Thanks in advance.Mark, you are not alone.
We also encountered this error using XI 3.0. We received the "Driver is not capable" error message when including date dimensions from a universe built on a BEx query. Looking at the universe, the date dimensions themselves were date fields, but all the date keys were listed as characters.
Our fix:
Replace all the date dimensions with the date keys listed below the dimensions. This is a little tricky because when you add the key into your webi query, it automatically adds the dimension. You have to manually remove the dimensions from the webi query after adding the key, and your report should run without the "Driver not capable" error message.
This is a serious bug, because now we have to train users building the webi queries to delete the date dimension. We cannot hide the dimension in the universe because it will also hide the key.
I guess another fix could be creating a new Dimension in the universe, and copying the properties from the key field into the new dimension...but if you have many dates, it's a big pain.
Hope this helps,
-Lee -
Report query not returning the field value from external table
hi
I have an issue regarding reports. I have a query having 4 fields from external table and remaining from db tables. the report query returns all the fields from the db tables and only 2 fields from external table. but the same query if I tried in plsql developer it returns all the fields values.
Can anyone please help me in this issue.
Thanks and Regards
kkDuplicate post?
value not displaying in report whereas it returns in plsql developer
value not displaying in report whereas it returns in plsql developer
Please log a SR if you do not get any reply to your thread instead of creating new one.
Thanks,
Hussein -
How can I get a query in the search field to open in a new tab or new window from the current window?
If you are searching via the Search Bar on the Navigation Toolbar, this preference can be changed to have searches there open in a Tab.
Type '''about:config''' in the Address Bar and hit Enter. Then answer "I'll be careful". Type this pref in the Search at the top.
'''browser.search.openintab''' = double-click to toggle to '''true''' -
Query : Addition of extra fields in the User Registration page of portal.
Hi All,
I have a query, about adding extra fields in the new user registration page of portal.
If you can suggest the required source files in details,inorder to incorporate two more fields.
Say, AGE and COMPANY,with the existing fields in the same page.
Along with this,can you please send the details of retrieving those information from backend and the backend functionalities associated with the SUBMIT button on the registration page.
Regards,
SudeepHi,
Your query is divided into two parts.
The first part is adding new fields into existing form. This feature comes under Branding of portal. Plz use the link below understanding the same and related help :
http://help.sap.com/saphelp_erp2005vp/helpdata/en/79/affe402a5ff223e10000000a155106/frameset.htm
The second part is retrieving the values from backend.Here it will be the UME database. You need to develop a logon.par file and replace the same in your portal.
Happy Customizing.
Sukanta Rudra -
Problem with the query of Sharepoint Calculated Fields
Hello,
I am developing an application in sharepoint 2013 foundation. but i have problems with a list, when executing a caml query on a calculated field. I try the solution of this blog
http://sptalks.wordpress.com/2013/03/25/query-on-calculated-field-problem
but i got no result
attentive to any comments
thanksHello,
This is my CAML Query
<View>
<ViewFields>
<FieldRef Name="ID" />
<FieldRef Name="PermMask" />
<FieldRef Name="FSObjType" />
<FieldRef Name="Nombre" AutoHyperLink="TRUE" />
<FieldRef Name="Apellidos" AutoHyperLink="TRUE" />
<FieldRef Name="Cargo" /><FieldRef Name="Edad" />
<FieldRef Name="Compa_x00f1_ia" />
<FieldRef Name="Created" />
</ViewFields>
<Query>
<GroupBy Collapse="TRUE" GroupLimit="30">
<FieldRef Name="Compa_x00f1_ia" />
<FieldRef Name="Edad" />
</GroupBy>
<OrderBy>
<FieldRef Name="ID" />
</OrderBy>
<Where>
<Contains>
<FieldRef Name="Ano" LookupId="FALSE" />
<Value Type="Text">2014</Value>
</Contains>
</Where>
</Query>
</View> -
In a query, for the selection field 'KNB1-ZWELS' a match-code isn't availab
Hi All,
Creating a query, for the selection field 'KNB1-ZWELS' a match-code isn't available.
Could anyone tell me the reason?
Thanks
GandalfHi,
Match Code Object is not available for the field ZWELS. If required, You need to contact a Developer for creating one . -
Adhoc query - length of service fields
Hi all,
I have question regarding the length of service fields in adhoc query (Actions infotype data fields PNP database).
When I select these fields I get different results according to reporting period; if i select a keydate then the service is calculated according to this date, but if I select a reporting period, then the service is calculated according to the start date of the reporting period.
Is this expected behaviour? Please let me know how this can be coded to reference the end date of the reporting period.
many thanksHi,
Please check OSS notes 333517 and 357093. Both notes, though from 2000, contain detailed functionality and recommendation around u201Clength of serviceu201D.
Hope this helps.
Donnie -
Creating a dynamic query by choosing the field and getting the report
Hi,
Is there a way to create a report by allowing the user to choose a field from the table and design a query based on that field.
Ex In a table students with fields
(StudentNo, StudentName,Age,Qualification,Hobbies, PlaceofBirth)
Is it possible to generate a query
select * from students where Hobbies=programming;
where the user can be given the option of selecting the field and the value (Hobbies, programming), the query is generated for that, then the report is designed for that query. How could the query be generated?
Regards,
ReshmaYou sure can ;)
Here's an example.
You can create a JComboBox and have the different categories of hobbies in there and then use ActionListener on the JcomboBox.
The code will be something like this
public void actionPerformed(ActionEvent ae)
if(ae.getSource()==combo) //assuming the JComboBox object is combo
String query=new String("");
String st = combo.getSelectedItem().toString();
Connection connection=DriverManager.getConnection("jdbc:odbc:DSN","user","password");
Statement stmt=connection.createStatement();
String qry="SELECT * FROM tablename WHERE hobby=";
String query=qry+st;
ResultSet rs=stmt.execute(query); //Then do whatever you want with the ResultSet object
} -
Inner Query relating to calculated field in main query
I have a query that has calculating fields in it.
What I am trying to do is Create another inner SELECT query similar to the one above but using the FP_Qty_Required calculated field in the main query?
Is this even possible?
Thanks in advance
AaronSorry. I did that because it looked a mess when I pasted it in.
SELECT P.ItemNumber, P.DeliveryWeek, D.StartDate AS WC_Date, S.SumOfSchedule_Qty, P.Planned_Production_Qty, P.Actual_Production_Qty, D.StartDate,
CASE WHEN S.SumofPartPallet < 0 THEN 'PART PALLET' ELSE '' END AS PartPallet, S.FirstOfIntouchRef, S.Pallet_Qty,
S.FirstOfTool_Number,
CAST(CASE WHEN S.SumOfSchedule_Qty > 0 THEN (S.SumOfSchedule_Qty - 1.0) / S.Pallet_Qty ELSE 0.00 END AS DECIMAL(18,
2)) AS DecNoOfPallets,
CEILING(CAST(CASE WHEN S.SumOfSchedule_Qty > 0 THEN (S.SumOfSchedule_Qty - 1.0) / S.Pallet_Qty ELSE 0.00 END
AS DECIMAL(18, 2))) AS QtyOfFullPallets,
CASE WHEN s.sumofpartpallet < 0 THEN s.sumofschedule_qty ELSE CEILING(CAST(CASE WHEN S.SumOfSchedule_Qty >
0 THEN (S.SumOfSchedule_Qty - 1.0)
/ S.Pallet_Qty ELSE 0.00 END AS DECIMAL(18, 2))) * s.pallet_qty END AS FP_Qty_Required,
(SELECT SUM(SumOfSchedule_Qty) AS Expr1
FROM dbo.SumOfSchedDelivery
AS s2
WHERE (ItemNumber = S.ItemNumber)
AND (DeliveryWeek <= S.DeliveryWeek)) AS Running_Sum,
FROM dbo.Production AS P INNER JOIN
dbo.SumOfSchedDelivery AS S ON P.ItemNumber = S.ItemNumber AND P.DeliveryWeek = S.DeliveryWeek INNER JOIN
barcoding.dbo.DeliveryWeeks AS D ON P.DeliveryWeek = D.DeliveryWeek INNER JOIN
dbo.TotalRequiredByItem AS T ON S.ItemNumber = T.ItemNumber
The above works. What I want to do next is after the Running_Sum to add another sub query similar to this:
(SELECT SUM(FP_Qty_Required) AS Expr2
FROM ???
WHERE (PD.ItemNumber = ItemNumber)
AND (PD.DeliveryWeek >= DeliveryWeek)) AS Running_FullPallet
FP_Qty_Required is a calculated field in the main query. -
SAP Query - Extract part of field
Hi,
I created a query with a local field. I want to extract only the last 3 characters of a field.
Is there a LEFT or RIGHT function I can use like in Excel?
The field I want to extract it from is 12 characters long.
Hope someone can help.
Thanks, LupeYou can not fetch only 3 characters directly
There are 3 ways you can achieve this
1> Create additional field in the infoset and code the logic. (If this report is used frequently, you should use this)
2> Download the output of query in the excel and perform excel actions (Use this if the report is not frequently required. Does not take much time to fetch 3 characters)
3> if the report format is fixed, you can create ABAP report and code yo fetch only 3 characters -
Hello friends,
Please help me to reduce the execution time of below query………
I am going to calculate some qty’s in my function. The below query is executed for each and every row , So How can I minimize the time of execution give me some tips because I have already check the explain plan and create all possible indexes but still it took too much time ….
Please give me some tips or suggestion to speed up the query…
SELECT SUM(BALANCE_INST_TO_RECD) BALANCE_INST_TO_RECD,
SUM(Qtyissued) Qtyissued,
SUM(qtyconsumed) qtyconsumed,
SUM(nvl(Qtyissued,QTYRECD)-nvl(qtyconsumed,0)) balance_to_consume
into l_BALANCE_INST_TO_RECD,l_ISSUE_QTY,l_ISSUE_CONSUME_QTY,l_BALANCE_TO_CONSUME_QTY
FROM
(select sum(Qtyissued) Qtyissued,
sum(QtyRECD) QtyRECD,
sum(BALANCE_INST_TO_RECD) BALANCE_INST_TO_RECD,
(select NVL(sum(v.qtyissued), 0)+NVL(sum(v.qty1), 0)+NVL(sum(v.qty2), 0)
from view_itemtran v
where v.entity_code = r.entity_code
and v.tcode = '0'
and v.tnature = 'WJREC'
and v.ref1_vrno = r.vrno
and v.ref1_tcode = r.tcode
and v.item_code = r.item_code
and trunc(v.slno)<>v.slno
AND not exists (select 1 from item_mast im
where im.item_code=v.item_code
and im.item_nature in ('SC','WA'))) qtyconsumed
from
(select ib.entity_code,
ib.div_code,
ib.tcode,
ih.vrno,
ih.vrdate,
ib.item_code,
ib.other_item_code service_code,
IB.Qtyissued,
IB.QtyRECD,
to_number(lhs_prod.get_reallocate_instruction_no(ih.entity_code,ib.div_code,null,a_recd_item_code,ih.vrno,ih.acc_code,a_other_item_code,'B')) BALANCE_INST_TO_RECD
from itemtran_head ih, itemtran_body ib
where ih.entity_code = ib.entity_code
and ih.tcode = ib.tcode
and ih.vrno = ib.vrno
and ih.entity_code =a_entity_code
and ih.tcode = '0'
and ih.vrno=NVL(a_issue_vrno,ih.vrno)
and ib.div_code=a_div_code
and ih.acc_code =a_acc_code
and ib.item_code=nvl(l_inst_input_item_code,ib.item_code)
and ((l_item_nature not in ('SC','WA') and ib.item_code=l_inst_input_item_code)
OR (l_item_nature in ('SC','WA') AND IB.ITEM_CODE IN (SELECT item_code
FROM VIEW_SCRAP_LOSS_ITEM
WHERE SCRAP_ITEM_CODE=a_recd_item_code
and item_code in (select item_code from view_itemtran
where entity_code=a_entity_code
and div_code=a_div_code
and tcode='0'
and tnature='WJISS'
and vrno=NVL(a_issue_vrno,VRNO)))))
--and nvl(IB.Qtyissued,0)>0
) r
group by entity_code,div_code,vrno,tcode,vrdate,item_code);
DB Version:-==Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
ThanksA few basic suggestions:
1) I'd take out the OR and replace it with 2 queries unioned together.
2) You say it's being called for every row. This implies another query is driving it. Can't you incorporate that query with this one so that most of the work is done in the database? If your SQL is being called in a post-query trigger on a form perhaps make a view incorporating this query and your base table.
3) You've got 2 INs here:
AND IB.ITEM_CODE IN
(SELECT item_code
FROM VIEW_SCRAP_LOSS_ITEM
WHERE SCRAP_ITEM_CODE =
a_recd_item_code
AND item_code IN
(SELECT item_code
FROM view_itemtran
WHERE entity_code =
a_entity_code
AND div_code =
a_div_code
AND tcode = '0'
AND tnature =
'WJISS'
AND vrno =
NVL (
a_issue_vrno,
VRNO)))))
Instead I'd make it EXISTS and then take those 2 queries and turn them into 1 query with view_scrap_loss_item and view_itemtran joined together. -
How do I speed up this query by ignoring computers off the network faster?
Good afternoon,
I am running the below script to query the entire domain for local admins. Could anyone reccomend a way to speed this up by more quickly skipping computers that aren't on the network? Currently, every time it reaches a computer that is not on the network
it hangs for up to 20 seconds (computers on the network return the data in less than a second). If I could decrease the ping time-out time, I could speed up this query tenfold.
Script pasted below - Thank you!!!
$Searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$Searcher.Filter = "(objectClass=computer)"
$Computers = ($Searcher.Findall())
md C:\Reports\IBX_Local_Admins_ALL
Foreach ($Computer in $Computers)
$Path=$Computer.Path
$Name=([ADSI]"$Path").Name
write-host $Name
$members =[ADSI]"WinNT://$Name/Administrators"
$members = @($members.psbase.Invoke("Members"))
$members | foreach {$_.GetType().InvokeMember("Name", 'GetProperty',
$null, $_, $null) | out-file -append C:\Reports\IBX_Local_Admins_ALL\$name.txtThis version will not fail no matter what is in the group.
function Get-LocalAdmins{
[CmdLetBinding()]
Param(
[Parameter(
Mandatory=$true,
ValueFromPipeline=$true,
Position=0
)]$computer
Process{
Write-Verbose "Polling system: $computer"
if(Test-Connection $Computer -quiet -count 1){
$group=[ADSI]"WinNT://$computer/Administrators"
$group.Invoke("Members") |
ForEach-Object{
New-Object PsObject -Property @{
Computer=$Computer
aDSPath=$_.GetType().InvokeMember('aDSPath', 'GetProperty',$null, $_, $null)
#UserID=$_.GetType().InvokeMember('Name', 'GetProperty',$null, $_, $null)
}else{
Write-Warning "System not found: $computer"
$computers=([adsisearcher]'(objectClass=computer)').FindAll() |%{$_.Properties['name']}
$computers | Get-LocalAdmins -verbose
¯\_(ツ)_/¯
Hi JRV,
Thank you for your help so far! When I ran the above version, it seemed to be going fine but it stopped at a certain point saying the script was "successful", but it only queried 148 computers. I should note that it is also the same 148 computers each time
I run it. No errors, it just stops and says successful. Any ideas?
TY! -
i was wondering if anyone has any ideas on how to speed this query up
SELECT NAME, trunc (opr_date + opr_hour/24-numtodsinterval(1,'second'), 'DDD') AS opr_date, PRICE,
Case OPR_HOUR When 0 THEN 24 ELSE OPR_HOUR END AS OPR_HOUR
FROM ze_data.pjm_edf_lmp_hourly_int
WHERE trunc (opr_date + opr_hour/24-numtodsinterval(1,'second'), 'DDD') between to_date ('2010/07/26', 'yyyy/mm/dd') and to_date ('2010/07/28', 'yyyy/mm/dd') and NAME in ('MISO')
ORDER BY OPR_DATE desc, opr_hour descThe data is stored in the database with hours 0 to 23 this code take hour 0 and switches it to hour 24 of the the day before. I was wondering if there was a way to speed up the query as it takes 8 seconds to run
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0Since you're comparing OPR_DATE to a date range, is there any need to add the time to OPR_DATE?
Would this work better? An index on OPR_DATE might help, but wouldn't an index on NAME be even better?
I don't know, just a guess. You haven't posted anything we can use.
SELECT NAME
,trunc (opr_date + opr_hour/24-numtodsinterval(1,'second'), 'DDD') AS opr_date
,PRICE
,Case OPR_HOUR When 0 THEN 24 ELSE OPR_HOUR END AS OPR_HOUR
FROM ze_data.pjm_edf_lmp_hourly_int
WHERE opr_date >= to_date ('2010/07/26', 'yyyy/mm/dd')
and opr_date <= to_date ('2010/07/28', 'yyyy/mm/dd')
and NAME in ('MISO')
ORDER BY OPR_DATE desc, opr_hour desc; -
Re: speeding up SPATIAL QUERY
hi! ,
Heres my sql statement ..
Select ODPM2001_I From DFT.URBANAREAS U
Where SDO_RELATE(U.GEOLOC, obTempPt, 'mask=CONTAINS querytype=WINDOW') = 'TRUE'; -- querytype=WINDOW
I have put a spatial index on U.GEOLOC ....
The sql statement takes too long
I pose my challenge to you ..
How can I speed up this query ?
From the DBA side and/or the PL/SQL side ...
thanks,
HarishHi,
The first thing you should try is updating to the latest patch release. Often there are performance enhancements included.
If you don't mind returning rectangles on whose boundary the point falls, use the anyinteract mask - it is the optimal mask to use if this situation allows it.
Hope this helps.
Maybe you are looking for
-
Dear All I am doing a scenario where I am receiving an asynchronous message in BPM and sending it Synchronously to the external system A. When I get a response from the external system I have to check a condition in BPM and based on that either have
-
Where clause and order by to DAO classes
Hi Is it ok(I mean design wise) to pass the 'where clause' conditions and order by clause as a parameter to the method of DAO class?
-
How do I obtain column names and types?
I am using Visual Studio C++ to connect and query an Oracle database using SQL commands. My code works, but I don't fully understand it because I'm new to Oracle and it is modified example code. I need to obtain column names and types for a known tab
-
Condition for Inbound MATMAS Idoc
Hi, Today we are receiving Idocs with Material Master data. IF the Material does not exist in SAP, it is created, otherwise, it is updated. Is there any way of only create the Material and if it does exist, do nothing? Do I have to copy FM IDOC_INPUT
-
Paused programmes going to live tv when unpaused
I was one of the many who was having the problems with recording programmes (only the first couple of minutes recording). However, the recent fix has sorted that but I'm still having problems with live tv. If I'm watching a programme and want to paus