sql server 2008 - TSQL Use record currently being inserted to select data in another table -


very new tsql...

i have following table called "tblinit":

account_num    userid        task_percent -----------    ------------  ------------ 1              john.smith    0.75 

i update "task percent" value in "tblraw" below.

account_num    userid        task_percent -----------    ------------  ------------ 1              john.smith    0.5 2              mary.mickle   0.9 3              don.donalds   1 

my plan use tsql stored procedure executed trigger on insert "tblinit". stored procedure move data "tblraw" (either merge or delete , insert) , truncate "tblinit" when procedure done. tblinit used stage incoming data.

i have read about scope_identity , @@identiy don't grasp concept. scope defined trigger executes stored procedure? in attempting own select statements using scope_identity , @@identity return "null" result. referenced msdn article seems return primary keys don't correlate data specified in article's example. reading incorrectly. want grab record inserted , use in query.

in essence, how update john.smith's new percentage value automatically on insert or, alternatively, how add new record entirely?

how update john.smith's new percentage value automatically on insert

this trigger used that:

create trigger tblinit_to_tblraw on tblinit insert begin     update r     set r.task_percent = i.task_percent     inserted         join tblraw r on i.userid = r.userid -- join on account_num instead? end 

this not take account new records (no existing match in tblraw). might want run if exists(... or merge.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -