简体   繁体   中英

T-SQL create function and update columns

I am new to the whole SQL Server / T-SQL area but I am basically trying to update a row in my database with a particular function and can't seem to find out how to do it.

First there are 2 columns latitude which has a value and TenLatMin which is null what I first do is check for all the null values

Select * 
from zipcodes 
where TenLatMin is null

DECLARE @LATMIN FLOAT
DECLARE @convert FLOAT

SET @convert= .14493
// I would like to get the latitudes from the Select and plug it there
SET @LATMIN= round(latitude - @convert,8)
// Then do the calculation and update the field
update zipcodes 
set TenLatMin =

The select works because I get a list of all the Null values now what I want to do is get the latitude of each row that has a Null value and use that inside the small @LATMIN calculation so that then I can set TenLatMin to that value..

Any suggestions would be great and as I said before each row already has a latitude value .

You can update all the records with missing TenLatMin is a single statement.

declare @convert float
set @convert = .14493

update zipcodes
set TenLatMin = ROUND(latitude - @convert, 8)
where TenLatMin is null

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM