Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 update field with data already in it

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2010-09-24 : 09:58:12

Currently I am updating user_def_fld_3 with bol_no, I also want to update another field called ar_reference but I want to concatenate the bol_no at the beginning of this field because there will already be data in it.

Is this possible??
ar_reference will have data like: Our Ref: PO002
During my update I would like to take the "Our Ref: PO002" and add
BOL: {field_name} to the front of it.

So that the ar_reference will look like this:
BOL: 234 Our Ref: PO002


begin
update oeordhdr_sql
set oeordhdr_sql.user_def_fld_3 = inserted.bol_no
from inserted INNER JOIN oeordhdr_sql on inserted.ord_no = oeordhdr_sql.ord_no
end

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-24 : 10:06:43
assuming all involved columns are character datatypes (else a convert would be needed):

begin
update oeordhdr_sql
set oeordhdr_sql.user_def_fld_3 = inserted.bol_no,
oeordhdr_sql.ar_reference = 'BOL: '+ inserted.bol_no + ' ' + isnull(oeordhdr_sql.ar_reference,'')
from inserted INNER JOIN oeordhdr_sql on inserted.ord_no = oeordhdr_sql.ord_no
end



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -