Update using select
Hi
I get an error when I try to run the update
create table table11( name varchar2(100),descr varchar2(100));
insert into table11 values ('a','abcd');
insert into table11 values ('b','abcde');
insert into table11 values ('c','abcdef');
create table table12( name varchar2(100),descr varchar2(100));
insert into table12 values ('a',null);
insert into table12 values ('b',null);
insert into table12 values ('d',null);
update table12 t
set descr= (select distinct a.descr from table11 a,table12 b where a.name=b.name)
Please help me correct the update statement
thanks
Hi,
The update statement written by you contains subquery which returns more than one record.
i.e the tables you are joining table11 and table12 contains common records of name "a" and "b".
That is why the subquery returning two records with desc's as "abcd" and "abde".
To run your update statement successfully make sure that the subquery return a single record.
Thanks,
Vinod
Similar Messages
-
Update using select/option question
Morning,
Does anyone have a snippet of code somewhere that I can use for an update select?
I need it to take the values from a database table and show the one the user selected like :
<SELECT NAME="DinnerChoice">
<OPTION SELECTED = 'Dinner1'>Dinner1
<OPTION = 'Dinner 2'>Dinner 2
<OPTION = 'Dinner 3'>Dinner 3
</SELECT>
Thanks,
LauraWell, if it is supposed to be a Webapplication and you need to generate HTML via PLSQL then you should code something like this:
SQL> BEGIN
/* Just necessary in SQL*Plus (initialization) */
OWA.cgi_var_name (1) := 1;
OWA.cgi_var_val (1) := 1;
OWA.init_cgi_env (1, OWA.cgi_var_name, OWA.cgi_var_val);
HTP.formSelectOpen ('DinnerChoice');
/* Choose your table here*/
FOR c IN (SELECT 'Dinner' || ROWNUM d
FROM user_objects
WHERE ROWNUM <= 3)
LOOP
HTP.formselectoption (cvalue => c.d,
cselected => CASE
WHEN c.d = 'Dinner1'
THEN 1
END
END LOOP;
HTP.formSelectClose ();
/* Just necessary in SQL*Plus */
HTP.showpage;
END;
Content-type: text/html
Content-length: 96
<SELECT NAME="DinnerChoice">
<OPTION SELECTED>Dinner1
<OPTION>Dinner2
<OPTION>Dinner3
</SELECT>
PL/SQL procedure successfully completed. -
Multiple columns and rows update using select staement
i am trying to update the 2 colums of a table based on the cursor result set with key values are matching.
DECLARE
CURSOR update_master
IS
SELECT B.cust_num,c.cust_num,
B.cust_name,B.cust_bal
FROM
Table_one B
JOIN
Table_two C
ON B.cust_num= C.cust_num;
BEGIN
FOR master_rec IN update_master
LOOP
UPDATE Table_three
SET col1 = master_rec.cust_name,
Col2 = master_rec.cust_bal,
Where WHERE Cust_num = master.cust_num;
END LOOP;
COMMIT;
END;
The 3 tables are having around 50000 records individually............
It is taking too much of time to execute......more than 6 minutes......
how can we optimize it?? can we write this update statement directly? instead of writing it in procedure?Here's a general approach:
update some_table s
set (s.col1, s.col2) = (select x.col1, x.col2
from other_table x
where x.key_value = s.key_value
where exists (select 1
from other_table x
where x.key_value = s.key_value
; -
Update Statement using SELECT statement
The following select query return 1 record to me
[code]
select deptno , dname, empno , max_date, max(v_num)
from (select d.deptno , d.dname , e.empno ,max (ver_date) over(partition by d.id ,d.no) max_date ,v_num
from emp e ,dept d
where e.deptno=d.deptno and e.dname = d.dname and e.empno=1 and d.deptno =3 )
group by deptno , dname, empno , max_date
[/code]
Now I need to update the above value to the emp table itself
In emp table for the empno=1 I need to update the columns mx_Date and v_num columns with the above last 2 columns in the select statement (max_date, max(v_num) )
How can I write the update statement for this.
Thank YouSomething like this
merge into emp e1
using (
select deptno
, dname
, empno
, max_date
, max(v_num) v_num
from (
select d.deptno
, d.dname
, e.empno
, max (ver_date) over(partition by d.id , d.no) max_date
, v_num
from emp e
, dept d
where e.deptno = d.deptno
and e.dname = d.dname
and e.empno = 1
and d.deptno = 3
group
by deptno
, dname
, empno
, max_date
) e2
on (
e1.empno = e2.empno
when matched then
update set e1.mx_date = e2.max_date,
e1.v_num = e2.v_num -
When is SELECT FOR UPDATE used
DB version:10gR2
Since another thread of mine on this subject didn't go well, i am starting another thread.
When exactly is SELECT..FOR UPDATE statement used? With the exception of using SELECT...FOR UPDATE in CURSOR declaration, I've rarely seen SELECT ...FOR UPDATE being used explicitlyby PL/SQL gurus in our firm. Why didn't they use SELECT..FOR UPDATE(i mean a stand alone SELECT FOR UPDATE, <em>not as a part of Cursor</em>) to lock rows before UPDATE/DELETE/INSERT in their codes?
Edited by: M.Everett on Oct 20, 2008 12:00 PM
edited the initial post to let the users know that I am refering to a stand alone SELECT FOR UPDATE statement, not the part of a cursorM.Everett wrote:
What i gather from various sources in the Internet:
1. SELECT FOR UPDATE is used mainly on CURSORs and very rarely used as a stand alone statement (if this is not the case you would have seen SELECT FOR UPDATE statements before every UPDATEs and DELETEs in PL/SQL codes)
2. Stand alone SELECT FOR UPDATEs are used mainly when dealing with CLOB, BLOB
Am i right in making these conclusions?1. This is probably a fair assumption.
2. Not really. SELECT FOR UPDATE is not a requirement when dealign with (C|B)LOBs.
SELECT FOR UPDATE allows an easy form of reference when you come to update rows in a cursor loop (although cursor loops should be rarely used), because rather than having to include a where condition on key columns you can just refer to the CURRENT ROW. Obviously, the main reason for using SFUs is the locking and this can become a requirement in some business environments where a user "picks up" a record to deal with and other users will then not see that record in their list or be able to select it for themselves.
;) -
Use select & update(query) at the same time
I'm sorry to trouble you.
I am racking my brains to find a solution to the problem.
I don't search a problem in my source.
I maked every effort.
I am tired to death.
I wanna use (select & update(query)) at the same time.
The Source compiled but have not access to DB
plz help me.
Can you give me a hand?
sorry my bad English..
link my source
http://www.netian.com/~111nice/bangnew.javacan you clearly explain whats problem and what error your are getting
-
If you are attempting to update using a Mac or PC with which you do not normally sync
what happens when "If you are attempting to update using a Mac or PC with which you do not normally sync", & they say in step 2 or 3 in order not to loose your stuff "If you are updating your iOS device on a computer with which you do not normally sync , or if you disconnect your device before the sync process is complete, you may notice that some media content that was previously on your device is no longer there. You can restore this content by syncing with the Mac or PC with which you normally sync."
now what if the pc that was originally used to sync my ipod , has corrupt or bad systems files that are causing it from working correctly...? when i plug it in to the o.g. operating sysytems (win xp) it doesnt ever recognize or discover the ipod through itunes. the pc will pop up the "cameras been plugged in, what would you like to do...?" but nothing thru itunes. now if i reboot & run the windows 7 operating system w/itunes that has backed my ipod before & synced a few times as well, but not the o.g. op system used from the beginning (the very initial set up done on the ipod) it works fine, but DOES give me the warning "updating to 5.0 willdelete some of your apps & media, including ... ....will only preserve contacts, calenders," ....etc.
MY HUGE CONCERN IS if i do hit update & go through w/it, & not having been able to sync it to the one normally used to sync my ipod, will that back up i made be able to restore my game seetings, GAME SAVES, & data achievement type information....?
please, i'm very hesitant to go through w/it, so if you can please help me out here & let me know asap.....i canimagine you're all busy busy, so i thank you for your time here w/this
thank you
mike z
[email protected]Not that hard. One the computer you are using do the following:
- Transfer iTunes purchases.
iTunes Store: Transferring purchases from your iOS device or iPod to a computer
- Transfer other music using a third-party program like one of those discussed here.
Copy music
- If you have synced photos you need a paid program like TouchCopy or PhoneView
- When all the media in on the computer, connect the iPod to the computer and make a backup by right clicking on the iPod under Devices in iTunes and select Back Up
- Restore the iPod from that backup.
That computer is now your syncing computer. Note that the iPod backup that iTunes makes does not included synced media like apps or music. -
Hi Friends,
I am using Oracle 8.1.6 Server, & facing problems while retrieving data from a PL/SQL Table:
CREATE or REPLACE PROCEDURE test_proc IS
TYPE tP2 is TABLE of varchar2(10); --declared a collection
dt2 tP2 := tP2('a','b','c');
i NUMBER(8);
begin
SELECT COUNT(*) INTO i FROM TABLE(CAST(dt2 as tP2));
DBMS_OUTPUT.PUT_LINE('**'||i);
end;
While executing the above procedure, I encountered foll. error:
ERROR at line 1:
ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL execution], [], [],
ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [], [], [], [], []
ORA-06553: PLS-801: internal error [0]
Can anyone please help me, where the problem is??
Is it Possible to retrieve data from PL/SQL TABLE using SELECT statement? & How ?
Thanks in advance.
Best Regards,
Jay Raval.Thanks Roger for the Update.
It means that have to first CREATE TYPE .. TABLE in database then only I can fire a Select statement on that TYPE.
Actually I wanted to fire a Select statement on the TABLE TYPE, defined & declared in PLSQL stored procedure using DECLARE TYPE .. TABLE & not using CREATE TYPE .. TABLE.
I was eager to know this, because my organization is reluctant in using CREATE TYPE .. TABLE defined in the database, so I was looking out for another alternative to access PL/SQL TABLE using Select statement without defining it database. It would have been good if I could access a PLSQL TABLE using Select statement Declared locally in the stored procedure.
Can I summarize that to access a PL/SQL TABLE using SELECT statement, I have to first CREATE TYPE .. TABLE?
If someone have any other idea on this, please do let me know.
Thanks a lot for all help.
Best Regards,
Jay Raval.
You have to define a database type...
create type tP2 is table of varchar2(10)
CREATE OR REPLACE PROCEDURE TEST_PROC
IS
dt2 tP2 := tP2('a','b','c');
i NUMBER(8);
begin
SELECT COUNT(*) INTO i FROM TABLE(CAST (dt2 AS tP2));
DBMS_OUTPUT.PUT_LINE('**'||i);
end;
This will work.
Roger -
Cant' update while select is active in read-committed mode
Hi All
I try to execute my java program the following error is comming
"cant' update while select is active in read-committed mode"
I am using prepraredStatement. The query is running successfully in QueryTool or Toad. But the Error is coming while execute this line
"stmt.executeUpdate(); "
pleaes solve my problem..
Thankx<br>Mmm, it seems same question Re: insert data problem</br>
<br>Nicolas.</br> -
iphoto 9.5 won't import photos from iPhoto 7.5. Library will not update using the iPhoto library upgrader application. Repeatedly says it can't locate photos even when told to cancel. I think the photos in question are in Nikon RAW format.
iPhoto 9.5 immediately tries to "upgrade" my library using the upgrader.
iPhoto 9.5 asks you to run the upgrader to prepare the library for 9.5. It then will update the library to its format.
You need to do the following:
1 - go to your Applications/Utilities folder and double click on the iPhoto Library Upgrader 1.1 application.
2 - select Choose Library, navigate to your iPhoto library, select it and let the upgrader do its thing.
3 - launch iPhoto 9.5 to open and finish the conversion of the library.
OT -
Update using an aggregate function
Hi all, while I'm a first time poster I've searched this forum as much as I can for a solution to this problem.
I'm trying to update an end_time column in a table using the values in the start_time column.
Here's a simplified example of what I want:
update table
set end_time = lag(start_time) over (order by start_time desc)-1;
So,
KEY START_TIME
1 7/1/1998
2 5/1/1998
3 4/1/1998
4 6/1/1995
becomes
KEY START_TIME END_TIME
1 7/1/1998
2 5/1/1998 6/30/1998
3 4/1/1998 4/30/1998
4 6/1/1995 3/31/1998
While I'd love this statement to be valid, does anyone know an alternative? I'd like to use the merge statement but I'm developing under an oracle 8i environment. I'm saving a pl loop as a last option.It is possible that with large data sets this first solution could be slow. The following query may choose full table scans and sort merges which might be more preferred for big tables. Also, the actual updates in the following MERGE will not execute unless the values have actually changed:
MERGE INTO foo f USING
SELECT a.start_date, min(b.start_date)-1 end_date
FROM foo a,
foo b
WHERE b.start_date(+) > a.start_date
GROUP BY a.start_date
) bar
ON (f.start_date = bar.start_date)
WHEN MATCHED THEN UPDATE SET f.end_date = bar.end_date
WHERE nvl(f.end_date,to_date('01-jan-1900','dd-mon-yyyy')) != nvl(bar.end_date,to_date('01-jan-1900','dd-mon-yyyy'));Greg Pike
http://www.singlequery.com -
Hint in Update or Select Statement in an inline query ??
Hi ,
I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary
where experience > 5 and empno = 55 )
where empno = 85Thanks
RedeYou would put the hint in the select statement as you have it, but it won't work until you alias your table name to "a" since that is how you are referencing it in the hint:
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary a
where experience > 5 and empno = 55 )
where empno = 85
NOTE I added the "a" right after the Salary table name AND you can only do parallel updates on partitioned table, but the select will run in parallel to at least get the data for you quickly.
To answer your other question about syntax, it is incorrect and there are a lot of ways to write it but a straight forward way would be to use the merge statement
merge into emp e
using (select /*+ full(s) parallel(s,4) */ s.salary from salary s where s.experience > 5) s
on (e.empno = s.empno)
when matched then update
set salary = s.salary; -
How to lock a row before update using UPDATE statement ?
I want to lock a row before updating using the UPDATE statement! is there any "reserved word" that I can append to an update statement so, that the row get locked!, also, will the lock gets released automatically once the update is done or do I have to explicitly release the lock?
how can I do this ?
any help is greatly appreciated.
Thanks,
Srini.For detail information, see http://otn.oracle.com/doc/server.815/a67779/ch4l.htm#10900
The lock will be released by "commit".
FOR UPDATE Examples
The following statement locks rows in the EMP table with clerks located in New York and locks rows in the DEPT table with departments in New York that have clerks:
SELECT empno, sal, comm
FROM emp, dept
WHERE job = 'CLERK'
AND emp.deptno = dept.deptno
AND loc = 'NEW YORK'
FOR UPDATE;
The following statement locks only those rows in the EMP table with clerks located in New York. No rows are locked in the DEPT table:
SELECT empno, sal, comm
FROM emp, dept
WHERE job = 'CLERK'
AND emp.deptno = dept.deptno
AND loc = 'NEW YORK'
FOR UPDATE OF emp.sal; -
Sessions/connections gets hang during update and select operations.
A table with 3 million records, which has customer details data.
Everyday application is executing select and update queries on that table.
Sessions/connections gets hang during update and select operations.
After checking ADDM report, following are the findings:
Please suggest the solutions
Findings and Recommendations
Finding 1: Row Lock Waits
Impact is 145.22 active sessions, 99.77% of total activity.
SQL statements were found waiting for row lock waits.
Recommendation 1: Application Analysis
Estimated benefit is 145.22 active sessions, 99.77% of total activity.
Action
Significant row contention was detected in the TABLE
"AVAYA.AIRTEL_CUSTOMER_MASTER" with object ID 82155. Trace the cause of
row contention in the application logic using the given blocked SQL.
Related Object
Database object with ID 82155.
Rationale
The SQL statement with SQL_ID "974vg65j29pmv" was blocked on row locks.
Related Object
SQL statement with SQL_ID 974vg65j29pmv.
UPDATE AVAYA.AIRTEL_CUSTOMER_MASTER SET PREFERRED_LANGUAGE = :1
WHERE ( AIRTEL_CUSTOMER_MASTER.MSISDN = :2 )
Rationale
The session with ID 50 and serial number 34525 in instance number 1 was
the blocking session responsible for 100% of this recommendation's
benefit.
Symptoms That Led to the Finding:
Wait class "Application" was consuming significant database time.
Impact is 145.22 active sessions, 99.77% of total activity.
Finding 2: Top SQL Statements
Impact is 46.39 active sessions, 31.87% of total activity.
SQL statements consuming significant database time were found. These
statements offer a good opportunity for performance improvement.
Recommendation 1: SQL Tuning
Estimated benefit is 46.39 active sessions, 31.87% of total activity.
Action
Investigate the UPDATE statement with SQL_ID "974vg65j29pmv" for
possible performance improvements. You can supplement the information
given here with an ASH report for this SQL_ID.
Related Object
SQL statement with SQL_ID 974vg65j29pmv.
UPDATE AVAYA.AIRTEL_CUSTOMER_MASTER SET PREFERRED_LANGUAGE = :1
WHERE ( AIRTEL_CUSTOMER_MASTER.MSISDN = :2 )
Rationale
The SQL spent only 0% of its database time on CPU, I/O and Cluster
waits. Therefore, the SQL Tuning Advisor is not applicable in this case.
Look at performance data for the SQL to find potential improvements.
Rationale
Database time for this SQL was divided as follows: 100% for SQL
execution, 0% for parsing, 0% for PL/SQL execution and 0% for Java
execution.
Rationale
SQL statement with SQL_ID "974vg65j29pmv" was executed 212 times and had
an average elapsed time of 2494 seconds.
Rationale
Waiting for event "enq: TX - row lock contention" in wait class
"Application" accounted for 100% of the database time spent in
processing the SQL statement with SQL_ID "974vg65j29pmv".**addm report **
ADDM Report for Task 'TASK_7526'
Analysis Period
AWR snapshot range from 5003 to 5004.
Time period starts at 08-JUL-13 11.00.27 AM
Time period ends at 08-JUL-13 12.00.45 PM
Analysis Target
Database 'AVAYADB' with DB ID 2878789264.
Database version 11.2.0.1.0.
ADDM performed an analysis of instance avayadb, numbered 1 and hosted at
NG-LA04AVAYA01.
Activity During the Analysis Period
Total database time was 563062 seconds.
The average number of active sessions was 155.63.
Summary of Findings
Description Active Sessions Recommendations
Percent of Activity
1 Row Lock Waits 155.44 | 99.88 1
2 Top SQL Statements 26.67 | 17.14 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Findings and Recommendations
Finding 1: Row Lock Waits
Impact is 155.4 active sessions, 99.88% of total activity.
SQL statements were found waiting for row lock waits.
Recommendation 1: Application Analysis
Estimated benefit is 155.44 active sessions, 99.88% of total activity.
Action
Significant row contention was detected in the TABLE
"AVAYA.AIRTEL_CUSTOMER_MASTER" with object ID 82155. Trace the cause of
row contention in the application logic using the given blocked SQL.
Related Object
Database object with ID 82155.
Rationale
The SQL statement with SQL_ID "974vg65j29pmv" was blocked on row locks.
Related Object
SQL statement with SQL_ID 974vg65j29pmv.
UPDATE AVAYA.AIRTEL_CUSTOMER_MASTER SET PREFERRED_LANGUAGE = :1
WHERE ( AIRTEL_CUSTOMER_MASTER.MSISDN = :2 )
Rationale
The session with ID 167 and serial number 6084 in instance number 1 was
the blocking session responsible for 100% of this recommendation's
benefit.
Symptoms That Led to the Finding:
Wait class "Application" was consuming significant database time.
Impact is 155.45 active sessions, 99.88% of total activity.
Finding 2: Top SQL Statements
Impact is 26.66 active sessions, 17.14% of total activity.
SQL statements consuming significant database time were found. These
statements offer a good opportunity for performance improvement.
Recommendation 1: SQL Tuning
Estimated benefit is 26.67 active sessions, 17.14% of total activity.
Action
Investigate the UPDATE statement with SQL_ID "974vg65j29pmv" for
possible performance improvements. You can supplement the information
given here with an ASH report for this SQL_ID.
Related Object
SQL statement with SQL_ID 974vg65j29pmv.
UPDATE AVAYA.AIRTEL_CUSTOMER_MASTER SET PREFERRED_LANGUAGE = :1
WHERE ( AIRTEL_CUSTOMER_MASTER.MSISDN = :2 )
Rationale
The SQL spent only 0% of its database time on CPU, I/O and Cluster
waits. Therefore, the SQL Tuning Advisor is not applicable in this case.
Look at performance data for the SQL to find potential improvements.
Rationale
Database time for this SQL was divided as follows: 100% for SQL
execution, 0% for parsing, 0% for PL/SQL execution and 0% for Java
execution.
Rationale
SQL statement with SQL_ID "974vg65j29pmv" was executed 707 times and had
an average elapsed time of 794 seconds.
Rationale
Waiting for event "enq: TX - row lock contention" in wait class
"Application" accounted for 100% of the database time spent in
processing the SQL statement with SQL_ID "974vg65j29pmv".
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Additional Information
Miscellaneous Information
Wait class "Commit" was not consuming significant database time.
Wait class "Concurrency" was not consuming significant database time.
Wait class "Configuration" was not consuming significant database time.
Wait class "Network" was not consuming significant database time.
Wait class "User I/O" was not consuming significant database time.
Session connect and disconnect calls were not consuming significant database
time.
Hard parsing of SQL statements was not consuming significant database time. -
How to re-write this self join update using a CTE
I would like to improve my performance on this update statement and would like to try re-writing using a CTE:
UPDATE "usr_sessions" "a" SET "is_ended_at_trustable" = 't'
WHERE (
EXISTS (
SELECT 1
FROM "usr_sessions" "b"
WHERE "a"."ended_at" = "b"."started_at"
AND "a"."usr_space_id" = "b"."usr_space_id"
AND "a"."account_id" = "b"."account_id"
) ) AND "a"."is_ended_at_trustable" IS NULL
Any help is greatly appreciated! Open to other suggestions as well if there is a better way!If I understood your description correctly, here's a way to accomplish the same thing, while dodging the need for the self join. The update itself won't be any faster, but the overall query leading to the update will likely be faster sans self-join.
(If my interpretation wasn't exactly what you meant, tweak the "partition by" clause).
MERGE is generally considered better then UPDATE, but your particular update isn't at risk for the shortcomings of update (still, Merge is newer, cooler, and more trustworthy).
Setup_Example_Data:
Declare @Usr_Sessions table (account_id int, usr_space_id int, is_ended_at_Trustable Char(1), started_at varchar(99), ended_at varchar(99))
Insert @Usr_Sessions
Select 1, 10, 't', 'A1', 'A1'
UNION ALL Select 2, 20, 'f', 'B1', 'B2'
UNION ALL Select 3, 30, NULL, 'C1', 'C1'
UNION ALL Select 4, 40, NULL, 'D1', 'D2'
UNION ALL Select 5, 50, NULL, 'E1', 'E2'
UNION ALL Select 5, 51, NULL, 'E3', 'E3'
UNION ALL Select 6, 61, NULL, 'F1', 'F2'
UNION ALL Select 6, 62, 't', 'F3', 'F3'
UNION ALL Select 6, 62, 'f', 'F4', 'F4'
Select 'Before', * from @Usr_Sessions
OP_Query:
BEGIN TRAN
UPDATE A SET is_ended_at_trustable = 't' from @usr_Sessions A-- Select * from @Usr_Sessions "a" --
WHERE (
EXISTS (
SELECT 1
FROM @usr_sessions "b"
WHERE "a"."ended_at" = "b"."started_at"
AND "a"."usr_space_id" = "b"."usr_space_id"
AND "a"."account_id" = "b"."account_id"
) ) AND "a"."is_ended_at_trustable" IS NULL
Select 'After 1', * from @Usr_Sessions
ROLLBACK TRAN /* Just to reset test data to original form, so second query below runs against original data */
Dodge_Self_Join:
With X as
Select *
, count(case when started_at = ended_at and is_ended_at_trustable is null then 'x' else null end)
over(partition by account_id, usr_space_id) as Updatable
From @Usr_Sessions
Update X
set is_ended_at_Trustable = 'T'
where Updatable > 0 -- EDIT -- fixed error, previously said "updatable = 1"
Select 'After 2', * from @Usr_Sessions
Maybe you are looking for
-
BB apps is not working, how to create BB email add? please help
BB apps is not working, how to create BB email add? please help
-
Complex mapping in xi 3.0
Hello all, I have some difficulty to make a mapping from the IDoc DESDAV.DELVRY03 to a standard structure for EDI. My structure of Idoc is : E1EDL37 vhart exidv E1EDL44 exidv E1EDL37-VHART allow us to know if it's a pallet or an item
-
D3dx9_42.dll error with windows 8.1
Hi I just got my new pc with windows 8.1 and when I try to play games (In this case with Civ 5) I get a d3dx9_42.dll error, I have read that you can fix this by installing the latest DirectX drivers but windows 8.1 install DirectX with windows upd
-
Check text in string AS3.0
So for my Flash class in school I'm making a game, this game has a keypad in it that if you enter the right code it unlocks the door. I have most of it down but am still confused. So far I have a dynamic text box and when you hit the number buttons I
-
I just purchased a MacBook Pro and transfered data form my old PowerBook G4 to it. I'm trying to delete a user account but it won't do it despite asking if I want to delete this account. Any ideas why and/or how I can delete it?