I need to update column in each empty row by data from procedure.
The problem is that I need a unique value for each record. Procedure returns it, but I don't know how to make it happen.
The results I got so far are same in every single row - remember that when I exec procedure it check table for existing values and gives me the unique value. How do I update every time other value by this procedure?
declare @ean varchar(40)
exec dbo.generateEAN 1, '', @ean output
update t
set Twr_Ean = @ean
from dbo.table t
where t.Code = ''
Try Scalar Functions ? Perhaps easier than Stored procedures for an in-line update statement. Here's a simple snippet. But performance degrades when working over a large dataset. You may want to rethink how you approach your problem.
create function dbo.ufn_mypower (@x int)
returns int with execute as caller as
begin return power( @x, 2 )
end
gocreate table updatewithfunction ( originalvalue int null
,calculatedvalue int null )insert updatewithfunction ( originalvalue ) values (1), (2), (3), (4), (5), (6)
update updatewithfunction set calculatedvalue = dbo.ufn_mypower(originalvalue)
where calculatedvalue is null and originalvalue >= 4select *from updatewithfunction
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.