sql - SQL麻烦!需要 IF/CASE 帮助
问题描述
所以。重新排列表格中的列格式以导入某些软件。以前的 DB 中有一个性别列,其中包含 M、F 或 U。新软件不会将 U 作为有效值,因此我需要一种方法来空白,同时保持 M 和 F 值相同。
SELECT Id AS Customerrefid,
SUBSTRING(Name, CHARINDEX(' ', "Name") + 1, LEN(Name) - (CHARINDEX(' ', "Name") - 1)) AS Surname,
LEFT("Name", CHARINDEX(' ', "Name")) AS Forename,
'0' AS Barcode,
"Address" AS "Address",
Postcode AS Postcode,
'UK' AS Countrycode,
Dob AS Dateofbirth,
Gender AS Gender,
' ' AS "Password",
Comment AS Notes,
' ' AS "Skintype",
Homephone AS Hometel,
' ' AS "Worktel",
Mobilephone AS Mobiletel,
Email AS Emailaddress,
'FALSE' AS Allowemail,
'FALSE' AS Allowsms,
'FALSE' AS Agreementsigned,
' ' AS Pin
FROM Customer;
select * from customer
解决方案
You could use a case
expression to turn U
s in to null
s:
CASE gender WHEN 'U' THEN NULL ELSE gender END AS gender
推荐阅读
- amp-html - 我的控制台中有关于我的 amp 故事的警告
- amazon-ec2 - 如何与其他开发者共享私钥
- oracle - 尝试在 Oracle 中读取文件时出现无效的文件操作异常
- batch-file - 检查空/批处理脚本中的字符串只有空格
- openshift - 与仅 OpenShift 容器平台相比,RedHat Openshift Application Runtimes 的价值是多少?
- vue.js - 如何更新 vue-codemirror MergeView 中“origLeft”的值?
- angular - 共享模块导出
- python - 正则表达式仅用于具有固定长度且没有数字前后数字的正则表达式,并且没有使用 \b
- rust - 为什么编译器让我在一个盒子里借另一个借?
- elasticsearch - 弹性搜索使用范围查询查找字段中的差异