Update column in t-sql 2012 stored procedure

In a t-sql 2012 stored procedure, I would like  to know if my solution to solve the problem is correct and/or if you have any other suggestion(s) on how I can complete the task I am listing below:

In an existing t-sql 2012 stored procedure, there is a table called 'Atrn' that is truncated every night.  The Table 'Atrn' has a column called 'ABS' that is populated with incorrect data.

The goal is to place the correct value into 'ABS' column that is located in the Atrn table while the t-sql 2012 stored procedure is excuting.
**Note: The goal is to fix the problem now since it is a production problem. The entire stored procedure that updates the 'dbo.Atrn' table will be rewritten in the near future.

My plan is to:

1. create a temp table called '#Atrnwork' that will contain the columns called,
Atrnworkid int, and ABSvalue with a double value.

2. The value in the column called Atrnworkid in the '#Atrnwork' table, will obtain its value from the key of the 'Atrn' called atrnid by doing a select into. At the same time, the value for ABSvalue will be obtained by running some sql when the select into occurs?

3. The main table called 'Atrn' will be changed with a update statement that looks something like:

Update Atrn
set ABS = ABSvalue
join Atrn.atrnid = #Atrnwork.Atrnworkid

In all can you tell me what a good solutiion is to solve this problem and/or display some sql on how to solve the problem listed above?





March 30th, 2015 11:19pm

You Are missing "From".

Sintaxe is this:

Update Atrn
set ABS = ABSvalue
from  Atrn 
join #Atrnwork.Atrnworkid = atrn.atrnId

Free Windows Admin Tool Kit Click here and download it now
March 30th, 2015 11:49pm

You have  not mentioned which sql you will run to get Absvalue. 

If its simple enough you can run it directly on table instead of using temptable. 

March 31st, 2015 1:37am

Hi

I think if you are not going to use the old ABS value, you probably dont need the second temp table.

Just get a back up of the table and do it.

In any case runing batch update on production tables sounds a little scary to me.

Regards

Aram

Free Windows Admin Tool Kit Click here and download it now
March 31st, 2015 1:51am

>> In an existing t-sql 2012 stored procedure

Where is it?!?

We know how to read code :-) There is no need for stories while you can and should post the code itself.

>> there is a table called

Again :-(
Where is the table?

Please post DDL+DML instead of stories :-)

>> create a temp table 

Fast reading and at first glance, I do not see why you need a temp table. You can use this "select query" during the update query.

March 31st, 2015 1:52am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics