问题描述
我需要清理 sql 表中的一些记录。不知何故,中间名首字母被放置在姓氏字段中的一些姓氏之前。
表格如下所示:
function OmitEvenorOdd(array,evenorOdd) {
let output = "";
let i = 0;
if (evenorOdd === 'odd') {
for (i = 0; i < array.length; i++) {
if (i % 2 == 0) {
if (i == array.length-2) {
output += array[i]
} else {
output += array[i] + '-'
}
}
}
} else {
for (i = 0; i < array.length; i++) {
if (i % 2 != 0) {
if (i == array.length-1) {
output += array[i]
} else {
output += array[i] + '-'
}
}
}
}
return output;
}
console.log(OmitEvenorOdd([1,'b','x',2,3,4],'odd'))
console.log(OmitEvenorOdd([1,'even'))
并非所有记录的前面都有中间名首字母和空格。我不能使用 TRIM 去掉每个记录中的前两个字符,因为它会弄乱那些正确导入姓氏的字符。有没有办法删除只有中间首字母的记录的第一个字符和空格?
提前致谢
解决方法
非常简单的解决方案。只需删除空间之前的所有内容。我在正确的轨道上使用 TRIM 而不是使用 RIGHT 和 LEN
更新 TABLE_NAME 设置 COLUMN_NAME = RIGHT(COLUMN_NAME,LEN(COLUMN_NAME) - CHARINDEX(' ',COLUMN_NAME)) 其中 CHARINDEX(' ',COLUMN_NAME) > 0