Simple update statement problem
hello experts sorry to bother everyone with such a mundane question but this is giving me a headache
i have 2 table ike and ike2
ike has c1, c2 and ike2 has c_1 and c_2
i like to set c2 on ike = to sysdate when c1=C_1
UPDATE (SELECT c1,c2,c_1, c_2 FROM ike , ike2 WHERE c1 = c_1 )
SET ike.C2 = sysdate ;
this seems really simple todo yet im having a hell of a time getting this to work can anyone point out the obvious.
Please
Hi,
Let me make sure I understand.
Some rows in ike have matching rows in ike2; that is ike.c1 = ike2.c_1.
For those rows that have matches, you want to set ike.c2 to SYSDATE.
For the rows the don't have a match, you don't want to change anything.
Is that it?
If you wanted to change all the rows, you would just say:
UPDATE ike
SET c2 = SYSDATE;If you only want to update some of the rows in ike, you add a WHERE clause at the end.
Either an EXISTS or an IN sub-query would make a good condition. Here's how to use IN:
UPDATE ike
SET c2 = SYSDATE;
WHERE c1 IN ( SELECT c_1
FROM ike2
);
Similar Messages
-
Deadlocks with simple UPDATE statement
I have in a C# program a dictionary and in SQL Server a stored procedure with a simple UPDATE statement. I process the dictionary in parallel. For each entry in my dictionary I call this stored procedure and I am getting deadlocks.
This is the UPDATE statement:
ALTER PROCEDURE [dbo].[UpdateImages]
@ICRTCode nvarchar(max),
@ICRTImage nvarchar(max)
AS
BEGIN
UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE() WHERE IDICRT = @ICRTCode
END
Can someone give me a hint as to why this would cause deadlocks? There are no other processes writing to this table. This is a table in a staging database.http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx
http://blogs.msdn.com/bartd/archive/2006/09/25/770928.aspx
Try change the statement a little bit
UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE()
FROM
Images
WITH (TABLOCK) WHERE IDICRT = @ICRTCode
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 -
Update statement problem for jdbc adapter
Hi all
In the jdbc sender adapter, I configured as follows:
Query statement
select * from pickdiff where tid is null
Update statement
delete from pickdiff where tid is null
I got following error message:
Database-level error reported by JDBC driver while executing statement 'delete from pickdiff where tid is null'. The JDBC driver returned the following error message: 'java.sql.SQLException: [SQLServer 2000 Driver for JDBC][SQLServer]Die Unterabfrage gab mehr als einen Wert zurück. Das ist ungültig, wenn die Unterabfrage auf =, !=, <, <= , >, >= folgt oder als Ausdruck verwendet wird.'. For details, contact your database server vendor.
If I change the Update statement to
update pickdiff set tid = 'sapxi' where tid is null
Then everything is ok.
Doese any one have some idea about this problem?
Regards
HuiHi,
The below statements are from SAP help...
http://help.sap.com/saphelp_nw04/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/frameset.htm
The UPDATE statement must alter exactly those data records that have been selected by the SELECT statement. You can ensure this is the case by using an identical WHERE clause. (See Processing Parameters, SQL Statement for Query, and SQL Statement for Update below).
● Processing can only be performed correctly when the isolation level for transaction is set to repeatable_read or serializable.
SQL statement for query: SELECT * FROM table WHERE processed = 0;
SQL statement for update: UPDATE table SET processed = 1 WHERE processed = 0;
processed is the indicator in the database.
please see if setting the isolation level would help....Also are you getting this error always or is it intermitent ?
Thanks,
Renjith -
Need a simple UPDATE statement for updating areas of the polygons
Hi,
I need a simple UPDATE SQL statement for updating areas of the polygons in a table shema.table (geom) with sdo_area function.
DejanDejan,
Maybe I don't understand your question but I will offer this:
update SOME_TABLE t set t.areasqft = SDO_GEOM.SDO_AREA(GEOM, 0.005) where t.geom.GET_GTYPE() = 3
This assumes a "feet" based SRID.
r,
dennis
Edited by: user633187 on Dec 1, 2008 9:04 AM -
Simple Update statement is taking too much time
Hi,
I have following update statement which is taking approx. 1 hour to update 4 lacs records. there is no any where clause in this statement and no any index on the updating column. there are only two indexes except primary key which are on other columns.
update cp_t_exception set module_cd='DEFAULT';
Please suggest me what can be the reason of this slowness?
Regards,
Sachin914014 wrote:
Hi,
please see the following details-
Database Version -
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
Execution Plan -
PLAN_TABLE_OUTPUT
Plan hash value: 2176582109
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | 422K| 3298K| 31637 (1)| 00:06:20 |
| 1 | UPDATE | CP_T_EXCEPTION | | | | |
| 2 | TABLE ACCESS FULL| CP_T_EXCEPTION | 422K| 3298K| 31637 (1)| 00:06:20 |
Regards,
SachinThanks Sachin.
I have certain suggestions for your situation: Please see which you like the most and can be implemented
_1. Modify the Update Statement_
Add the Complementary Set condition in the Where Predicate, thus eliminating the set of records that need not be updated.
viz.
update table table_name set column_name = 'DEFAULT' where column_name != 'DEFAULT';_2. Parallel Queries_
Check if your Software supports Parallel Query Execution. Also read the Parallel Hint for DML and Parallel_Index Hint.
_3. Create Table As Select (This option wouldn't really be required for such small amount of data.)_
You can create a New Table and drop the existing table.
a. Create a New Table new_table as select column_1.. columnN, decode(status, 'DEFAULT', 'DEFAULT', 'DEFAULT') from base_table; -- No Logging Mode
b. Build the Index, Triggers, Constraints.
c. Alter the table to LOGGING.
d. Drop the Base_table; -- Verify if the entire data in New_Table is same as Base_Table.
e. Rename the New_table to base_table.
Check the Suggestions 1 and 2 to compare the performance with the DML without using them. Let us know if you still face same problem. -
Update statement problem !!
Hi,
I need some specific features for my school project and BDB is almost providing me with this functionality. In my project, I want to provide the user with the functionality to provide the update statements from the user screen. I want to then take the user input in a java variable for manipulation of the xml data and display the end result. The only option I have for the user is to provide the xquery updates with the following syntax: ( I need this syntax for update statements as I use a parser to convert the user input to involve fuzziness):
"insert nodes <b4>inserted child</b4> after doc('dbxml:/test.dbxml/book)/Bookstore";
Now I am trying to run these with the below Code but I am not actually getting the required output. Can somebody help me to debug or fix this code for my requirement. I use the following xml data :
<Bookstore>
<Book>
<book_ID>1</book_ID>
<title>Harry Potter and the Order of the Phoenix</title>
<subtitle/>
<author>
<author_fname>J.K.</author_fname>
<author_lname>Rowling</author_lname>
</author>
<price>9.99<;;/price>
<year_published>2004</year_published>
<publisher>Scholastic, Inc.</publisher>
<genre>Fiction</genre>
<quantity_in_stock>28997</quantity_in_stock>
<popularity>20564</popularity>
</Book>
</Bookstore>
I have track points in my code to find the mistake and I get the following ouput.
Track 3
Track 3.1
Track 3.2-----
The code I use fails to compile the xquery statement with .prepare API.
import java.io.*;
import com.sleepycat.db.*;
import com.sleepycat.dbxml.*;
public class phone{
public static void main(String[] args)
String document1 = "C:/Documents and Settings/cjmadall/Desktop/BDB/book.xml";
String docName = "book";
XmlManager myManager = null;
XmlContainer myContainer = null;
try {
myManager = new XmlManager();
myContainer = myManager.openContainer("test.dbxml");
String myQuery = "insert nodes <b4>inserted child</b4> after doc('dbxml:/test.dbxml/book)/Bookstore";
// This Works and displays the entire document-> String myQuery = "collection('test.dbxml')";
// This Doesnt Work, ends with the above output -> String myQuery = "insert nodes <newNode>Some new text</newNode> after collection("dbxml:/test.dbxml")/Bookstore";
// collection('test.dbxml')/Bookstore";
System.out.println("Track 3 ");
XmlQueryContext managerContext = myManager.createQueryContext();
System.out.println("Track 3.1 ");
// Get a context for the document queries
// XmlQueryContext documentContext = myManager.createQueryContext();
System.out.println("Track 3.2 ");
// Prepare the XmlManager query
*XmlQueryExpression managerQuery = myManager.prepare(myQuery, managerContext);*
System.out.println("Track 3.3 ");
// Perform the query.
XmlResults results = managerQuery.execute(managerContext, 0);
// Display the result set
System.out.println("Track 3.4 ");
XmlValue value;
while ((value = results.next()) != null){
System.out.println(value.asString());
System.out.println("Track 3.5 ");
results.delete();
managerQuery.delete();
// documentContext.delete();
managerContext.delete();
} catch (XmlException e) {
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (myContainer != null) {
myContainer.close();
if (myManager != null) {
myManager.close();
} catch (XmlException ce) {
// Exception handling goes here
}//end finally
Thanks.I was using a old version of BDB and the latest version fixed this issue.
-
Writing an update statement in oracle forms 9i
Hi ,
I have a problem situation in which
I am fetching values from a cursor and a recod group into two data block items text box and combo box respectively .
Both the data is fetched from different tables .
Now based on the selection from combo box I have to update the selected value in another table by writing an update statemet .
I have created a button and on the trigger event of when button pressed I wrote a simple update statement but it's not working that way .
Kindly help me how to write manual update statements in oracle forms 9i
I can't used the update buil in of forms as I want to update in a table which is not mentioned in the property pallete of data block
please helpI just wrote a procedure
PROCEDURE update_current IS
BEGIN
update table abc set xculumn= :block_name.item_name2 where ycolumn = :block_name.item_name1 ;
commit;
and I called the procedure from a when button pressed trigger
it gave an error invalid identifier abc ( which is table name)
pls help
I am trying to do it with form_ddl(update_query)
but here I am facing another problem
I have update_query = 'update table abc set xculumn= ' || :block_name.item_name2 || 'where ycolumn = '||:block_name.item_name1
now since xculumn and y column are varchar type so I suppose while preparing the query I have to concatenate single quotes ( ' ) at the start and end
but i am facing problems in doing so
please tell me an alternative way or how to concatenate single quotes in the above update_query variable -
SqlDependency causing delays to UPDATE statements
I have a win forms application which uses SqlDependency to monitor an orders table for changes (ie when goods are shipped etc). The SQL statement works fine but I am having trouble with other SQL statements wanting to update the orders table whilst
the SqlDependency is monitoring the table.
Initially I thought it was down to the transaction containing the update statements but if I take just one simple update statement and run it in SQL Management Studio, I get the same delay between 10 and 20 seconds. It appears to be the case for just
this one table which is monitored, other tables which are included in the SqlDependency SQL statement through inner joins are updated fine (<1 second).
Anyone any ideas on what could cause this or where to start troubleshooting?
Also, this is in a production system and the table in question has circa 19k rows. I don't see this problem in my dev system which has fewer rows.
ChrisHello,
I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.
Thank you for your understanding and support.
Regards,
Fanny Liu
If you have any feedback on our support, please click here.
Fanny Liu
TechNet Community Support -
OWB won't generate an UPDATE statement
I have a mapping which I am attempting to do a MERGE (UPDATE/INSERT) statement on. The mapping validates, however, when I generate the SQL for the mapping, it does not generated the MERGE statement SQL. It is like the portion of the mapping does not even exist. I went ahead and tried to do a simple UPDATE statement, and the same problem exists...it will not generate the portion of the mapping that I try to do the UPDATE statement on. I can do an insert statement and the code will be generated, but the UPDATE is a problem.
I have the same problem.
I use one source table and one target table (ID filled by a sequence, another column is the unique key)
I want to use the INSERT/UPDATE as loading type, but OWB creates only an INSERT statement (without an update) and no MERGE-statement.
If I use the UPDATE/INSERT as loading type, OWB creates two cursors (update and insert).
What's going wrong?
And why doesn't OWB create a merge-statement??
I've created mappings like this one and that worked fine.
Is it a bug in OWB?
(And when I delete the sequence, still the same (wrong) result)
Regards,
Maurice -
Hi ,
I have the following qurey and i want to design a simple mapping of it.. I dont want the code to generate MERGE statement. I want to do it by generateing a simple Update statement.
Update
select
a.customer_id tgt_customer_id,
a.customer_name tgt_customer_name ,
a.customer_address1 tgt_customer_address1 ,
a.customer_address2 tgt_customer_address2 ,
a.customer_address3 tgt_customer_address3 ,
b.customer_id src_customer_id,
b.customer_name src_customer_name ,
b.customer_address1 src_customer_address1 ,
b.customer_address2 src_customer_address2 ,
b.customer_address3 tgt_customer_address3
from customer_table1 a , customer_table2 b
where a.customer_id = b.customer_id
) set tgt_customer_name = src_customer_name,
tgt_customer_address1 = src_customer_address1 ,
tgt_customer_address2 = src_customer_address2 ,
tgt_customer_address3 = tgt_customer_address3
Thanks,
R-Hi,
If you have set the lang as plsql, I dont think its possible to have a code with just update statement. In your case, I don't think merge statement will have any problem. Infact it will give you better performance.
Hardeep -
Hi all,
I have a simple update query problem. I have four tables
activist(activist_id,first_name,last_name,c_state),
membership(activist_id,g_n_id),
group_network(g_n_id,g_n_type_id),
school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
Here is the query for the states which are null
select distinct a.activist_id,a.first_name,a.last_name,
a.c_state,sd.state from activist a,membership m,
group_network g,school_group_det sd where
a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
order by a.activist_id
I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
Pleae any one help me
Thanks
SrinivasHi all,
I have a simple update query problem. I have four tables
activist(activist_id,first_name,last_name,c_state),
membership(activist_id,g_n_id),
group_network(g_n_id,g_n_type_id),
school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
Here is the query for the states which are null
select distinct a.activist_id,a.first_name,a.last_name,
a.c_state,sd.state from activist a,membership m,
group_network g,school_group_det sd where
a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
order by a.activist_id
I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
Pleae any one help me
Thanks
Srinivas -
SQL Update statement taking too long..
Hi All,
I have a simple update statement that goes through a table of 95000 rows that is taking too long to update; here are the details:
Oracle Version: 11.2.0.1 64bit
OS: Windows 2008 64bit
desc temp_person;
Name Null? Type
PERSON_ID NOT NULL NUMBER(10)
DISTRICT_ID NOT NULL NUMBER(10)
FIRST_NAME VARCHAR2(60)
MIDDLE_NAME VARCHAR2(60)
LAST_NAME VARCHAR2(60)
BIRTH_DATE DATE
SIN VARCHAR2(11)
PARTY_ID NUMBER(10)
ACTIVE_STATUS NOT NULL VARCHAR2(1)
TAXABLE_FLAG VARCHAR2(1)
CPP_EXEMPT VARCHAR2(1)
EVENT_ID NOT NULL NUMBER(10)
USER_INFO_ID NUMBER(10)
TIMESTAMP NOT NULL DATE
CREATE INDEX tmp_rs_PERSON_ED ON temp_person (PERSON_ID,DISTRICT_ID) TABLESPACE D_INDEX;
Index created.
ANALYZE INDEX tmp_PERSON_ED COMPUTE STATISTICS;
Index analyzed.
explain plan for update temp_person
2 set first_name = (select trim(f_name)
3 from ext_names_csv
4 where temp_person.PERSON_ID=ext_names_csv.p_id
5 and temp_person.DISTRICT_ID=ext_names_csv.ed_id);
Explained.
@?/rdbms/admin/utlxpls.sql
PLAN_TABLE_OUTPUT
Plan hash value: 3786226716
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | 82095 | 4649K| 2052K (4)| 06:50:31 |
| 1 | UPDATE | TEMP_PERSON | | | | |
| 2 | TABLE ACCESS FULL | TEMP_PERSON | 82095 | 4649K| 191 (1)| 00:00:03 |
|* 3 | EXTERNAL TABLE ACCESS FULL| EXT_NAMES_CSV | 1 | 178 | 24 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - filter("EXT_NAMES_CSV"."P_ID"=:B1 AND "EXT_NAMES_CSV"."ED_ID"=:B2)
Note
- dynamic sampling used for this statement (level=2)
19 rows selected.By the looks of it the update is going to take 6 hrs!!!
ext_names_csv is an external table that have the same number of rows as the PERSON table.
ROHO@rohof> desc ext_names_csv
Name Null? Type
P_ID NUMBER
ED_ID NUMBER
F_NAME VARCHAR2(300)
L_NAME VARCHAR2(300)Anyone can help diagnose this please.
Thanks
Edited by: rsar001 on Feb 11, 2011 9:10 PMThank you all for the great ideas, you have been extremely helpful. Here is what we did and were able to resolve the query.
We started with Etbin's idea to create a table from the ext table so that we can index and reference easier than an external table, so we did the following:
SQL> create table ext_person as select P_ID,ED_ID,trim(F_NAME) fst_name,trim(L_NAME) lst_name from EXT_NAMES_CSV;
Table created.
SQL> desc ext_person
Name Null? Type
P_ID NUMBER
ED_ID NUMBER
FST_NAME VARCHAR2(300)
LST_NAME VARCHAR2(300)
SQL> select count(*) from ext_person;
COUNT(*)
93383
SQL> CREATE INDEX EXT_PERSON_ED ON ext_person (P_ID,ED_ID) TABLESPACE D_INDEX;
Index created.
SQL> exec dbms_stats.gather_index_stats(ownname=>'APPD', indname=>'EXT_PERSON_ED',partname=> NULL , estimate_percent=> 30 );
PL/SQL procedure successfully completed.We had a look at the plan with the original SQL query that we had:
SQL> explain plan for update temp_person
2 set first_name = (select fst_name
3 from ext_person
4 where temp_person.PERSON_ID=ext_person.p_id
5 and temp_person.DISTRICT_ID=ext_person.ed_id);
Explained.
SQL> @?/rdbms/admin/utlxpls.sql
PLAN_TABLE_OUTPUT
Plan hash value: 1236196514
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | 93383 | 1550K| 186K (50)| 00:37:24 |
| 1 | UPDATE | TEMP_PERSON | | | | |
| 2 | TABLE ACCESS FULL | TEMP_PERSON | 93383 | 1550K| 191 (1)| 00:00:03 |
| 3 | TABLE ACCESS BY INDEX ROWID| EXTT_PERSON | 9 | 1602 | 1 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | EXT_PERSON_ED | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
4 - access("EXT_PERSON"."P_ID"=:B1 AND "RS_PERSON"."ED_ID"=:B2)
Note
- dynamic sampling used for this statement (level=2)
20 rows selected.As you can see the time has dropped to 37min (from 6 hrs). Then we decided to change the SQL query and use donisback's suggestion (using MERGE); we explained the plan for teh new query and here is the results:
SQL> explain plan for MERGE INTO temp_person t
2 USING (SELECT fst_name ,p_id,ed_id
3 FROM ext_person) ext
4 ON (ext.p_id=t.person_id AND ext.ed_id=t.district_id)
5 WHEN MATCHED THEN
6 UPDATE set t.first_name=ext.fst_name;
Explained.
SQL> @?/rdbms/admin/utlxpls.sql
PLAN_TABLE_OUTPUT
Plan hash value: 2192307910
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | MERGE STATEMENT | | 92307 | 14M| | 1417 (1)| 00:00:17 |
| 1 | MERGE | TEMP_PERSON | | | | | |
| 2 | VIEW | | | | | | |
|* 3 | HASH JOIN | | 92307 | 20M| 6384K| 1417 (1)| 00:00:17 |
| 4 | TABLE ACCESS FULL| TEMP_PERSON | 93383 | 5289K| | 192 (2)| 00:00:03 |
| 5 | TABLE ACCESS FULL| EXT_PERSON | 92307 | 15M| | 85 (2)| 00:00:02 |
Predicate Information (identified by operation id):
3 - access("P_ID"="T"."PERSON_ID" AND "ED_ID"="T"."DISTRICT_ID")
Note
- dynamic sampling used for this statement (level=2)
21 rows selected.As you can see, the update now takes 00:00:17 to run (need to say more?) :)
Thank you all for your ideas that helped us get to the solution.
Much appreciated.
Thanks -
How to tune the Update statement for 20 million rows
Hi,
I want to update 20 million rows of a table. I wrote the PL/SQL code like this:
DECLARE
v1
v2
cursor C1 is
select ....
BEGIN
Open C1;
loop
fetch C1 bulk collect into v1,v2 LIMIT 1000
exit when C1%NOTFOUND;
forall i in v1.first..v1.last
update /*+INDEX(tab indx)*/....
end loop;
commit;
close C1;
END;
The above code took 24 mins to update 100k records, so for around 20 million records it will take 4800 mins (80 hrs).
How can I tune the code further ? Will a simple Update statement, instead of PL/SQL make the update faster ?
Will adding few more hints help ?
Thanks for your suggestions.
Regards,
Yogini JoshiHello
You have implemented this update in the slowest possible way. Cursor FOR loops should be absolute last resort. If you post the SQL in your cursor there is a very good chance we can re-code it to be a single update statement with a subquery which will be the fastest possible way to run this. Please remember to use the {noformat}{noformat} tags before and after your code so the formatting is preserved.
David -
Is there a bulk update statement in 11g?
Hi everyone,
This is a pretty simple request but I cannot seem to find any documentation for it (at least on the 11g DB version).
I have a simple update statement:
UPDATE W_AP_XACT_FS SET DATASOURCE_NUM_ID = 5;
COMMIT;It probably seems strange why I would want to do that, but suffice it to say that I have no control over what value gets loaded into that column, however, I do need to correct it.
Either way, I want to make the above statement as efficient as possible.
What's the fastest way to perform a quick static update like that? Is there such a thing as a bulk update statement?
Thanks for the help!
-JoeI need something that works 100% of the time and doesn't hang & create a DB lock.It has to lock the records it's updating until you commit. You could commit more frequently via a procedural approach but that is generally considered a bad idea because it's slower, takes more resources and risks 'snapshot too old' errors. 'Hanging' can mean a number of things, so I'm not sure which scenario you need to avoid here apart from the update taking a long time. Maybe it's just processing a lot of rows, in which case you might be able to throw some more resources at it with parallel DML. Or maybe it's blocked by another session, in which case you can find out a lot from v$session, v$lock, dba_blockers etc.
UPDATE W_AP_XACT_FS SET DATASOURCE_NUM_ID = 5;Could there ever be any rows prior to the update that already have DATASOURCE_NUM_ID = 5? If so, adding
WHERE datasource_num_id != 5;(if datasource_num_id is mandatory) or something like
WHERE datasource_num_id != 5
OR datasource_num_id IS NULL;(if it's nullable) would reduce the number of rows needing to be processed.
Edited by: William Robertson on Aug 1, 2010 8:07 PM -
FOR XML causing high cardinality in update statement.
Wasn't really sure how to word this, but here it goes. I have a simple update statement that uses a sub-query to concatenate a column from a record set using the most recently recommended fashion of FOR XML. The row estimations through the XML reader show
as 42 million rows, but the actual rows are 18k'ish.
update d
set d.DraftDocumentReadyDate = stuff(isnull((select ', ' + convert(varchar, wa.WorkAudit_Date, 110)
from livelink.WAuditTrail wa inner join livelink.KUAF ku1
on wa.WorkAudit_PerformerID_Name = ku1.Name
where d.VolumeID = wa.WorkAudit_WorkID
and wa.WorkAudit_Task_Title = 'Draft Document'
and wa.WorkAudit_Status = 21
for xml path (''), type).value('.','nvarchar(4000)'), ''), 1, 2, '')
from #ltbl_DataDump d
Adding image of cardinality:
John M. CouchI would change this query a bit (since I like to simplify):
;with cte as (Select workAudit_workID, stuff(isnull((select ', ' + case when ku1.FirstName IS NULL and ku1.LastName IS NULL and ku1.Name IS NULL then 'None'
when ku1.FirstName IS NULL and ku1.LastName IS NULL then ku1.Name
else ku1.FirstName + ' ' + ku1.LastName
end
from livelink.WAuditTrail wa inner join livelink.KUAF ku1
on wa.WorkAudit_PerformerID_Name = ku1.Name
where wa.WorkAudit_WorkID = wa1.workAudit_workID
and wa.WorkAudit_Task_Title = 'Draft Document'
and wa.WorkAudit_Status = 24
for xml path (''), type).value('.','nvarchar(4000)'), ''), 1, 2, '') as DocName,
STUFF((SELECT ', ' + convert(varchar(20), wa.WorkAudit_Date, 110)
from livelink.WAuditTrail wa
where wa.WorkAudit_WorkID = wa1.workAudit_workID
and wa.WorkAudit_Task_Title = 'Draft Document'
and wa.WorkAudit_Status = 24
for xml path ('')),1,2,'') as Dates
FROM livelink.WAuditTrail wa1
where wa1.WorkAudit_Task_Title = 'Draft Document'
and wa1.WorkAudit_Status = 24
GROUP BY wa1.workAudit_WorkId)
MERGE #ltbl_DataDump d
USING cte ON d.WolumeID = cte.workAudit_Workid
WHEN MATCHED
THEN UPDATE
SET
DraftDocumentStartedPerformer = cte.DocName,
d.DraftDocumentStartedDate = cte.Dates
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Maybe you are looking for
-
I have set up all my email contacts in my iphone 4. Am i able to set up a group as i often sent an email to 42 contacts?
-
Formatting an external HD for mac AND pc?
I need to use my 500g external hard drive on both macs and pcs for mostly music files. I cannot modify ntsf files on my mac and my pc will not even read the mac format. I heard that the FAT32 is supported by both systems but how do i use disk utility
-
Facebook keeps saying sorry, something went wrong when try to open on my iphone
Facebook keeps saying, sorry, something went wrong when I try to open it. How can I resolve this issue?
-
Is there any java api available to get the process identifier ?
Hai, I am in need to get the process identifier of a running process. Is there any API available or any shell script which can be used in exec command to get it. Thanks in Advance. Kavitha M.
-
Stand-Alone exe not seeing my VISA instruments
Hello, I am attempting to build a standalone installer application from my VI using LV 7.1 on a Win 2k machine. I have gone through the build application wizard making sure to enable hardware configuration checkbox and select the desired VISA TCP/IP