View previous topic :: View next topic
|
Author |
Message |
Sachin Ghadage
New User
Joined: 06 Nov 2009 Posts: 3 Location: pune
|
|
|
|
Hi,
I would like to write query in such a way that:
It will update first 100 rows out of 500 rows selectd.
For e.g.
Update Table_Name first 100 only
set Err_Ind= 'Y'
where userid= 'ABC';
Here Where clouse will selct 500 rows but out of that I have to update first 100 .
Whats a correct syntax?.. is it possible? |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
You need to tell the order or else what you are saying is meaningless in RDBMS. |
|
Back to top |
|
|
ajeshrn
New User
Joined: 25 Mar 2009 Posts: 78 Location: India
|
|
|
|
Hi Sachin,
I am not sure how we do using a single query, but we can do it using mutliple queries using Session tables in SPUFI
Steps are as followed:
1) Create a temperory session table with required columns.
2) Insert with select into the session tables.(Multi Insert)
3) Do an update against the temporary session table.
4) Finally update the actual tables joining the session table.
Sequence should be in this order
Ex:
Consider session table is created and record is inserted and you are trying to change the Designation from trainee to Programmer.
Actual TB
Emp ID Emp Nm Emp Desg
--------------------------------------
01 A Trainee
02 B Trainee
Session TB
Emp ID Emp Nm Emp Desg
--------------------------------------
01 A Trainee
02 B Trainee
First change the record in Session table to Programmer
Session Table after update
Emp ID Emp Nm Emp Desg
--------------------------------------
01 A Programmer
02 B Programmer
Finally,
Update status in actual table joining the employee id's between the master and session table.
The whole set of queries should be executed in the correct sequence for this to work. |
|
Back to top |
|
|
ajeshrn
New User
Joined: 25 Mar 2009 Posts: 78 Location: India
|
|
|
|
While inserting the record to session table using insert with select do a fetch first 100 records only |
|
Back to top |
|
|
|