我有这个SQL查询:
DECLARE @table TABLE (Gender VARCHAR(15))
INSERT INTO @table
VALUES
('F'),
('AAA'),
('M'),
('null'),
('NULL')
如何编写标量函数来清除此Gender列,插入F或M代替“AAA”或这些空值。
答案 0 :(得分:0)
你可以从这开始,但是你确定它应该是M还是F的条件是什么?
UPDATE yourTable
SET gender =
CASE
WHEN -- your condition where you determine if it should be M --
THEN 'M'
ELSE 'F'
END
WHERE LOWER(gender) NOT IN ('m', 'f')
答案 1 :(得分:0)
create yourTable
(Gender bit not null)
位只有0
或1
select
case gender
when 1 then 'F'
when 0 then 'M'
end as gender
from yourTable
或在表中使用char(1)