1

All I have what seems to be a pretty straight forward question, that I haven't been able to figure out. For example, if I have a text string like T6L 7H5. Using SQL I need to remove the inner white space from this string so that it displays like T6L7H5.

Things to consider:

  • Teradata (v.13.10) is my RDBMS, so REPLACE('T6L 7H5', ' ', '') is not an option here.
  • On this particular server I am a business user w/ very limited permissions so creating a UDF is not an option either.
4

3 回答 3

2

无法测试这个,所以吐球,但你应该能够利用子字符串和位置:

SELECT SUBSTRING('T6L 7H5', 1, POSITION (' ' IN 'T6L 7H5')-1) || SUBSTRING('T6L 7H5',  POSITION (' ' IN 'T6L 7H5')+1, CHARACTER_LENGTH('T6L 7H5') -  POSITION (' ' IN 'T6L 7H5') )

如果该字段的格式与您的示例一致,则:

substring('T6L 7H5',1,3)||substring('T6L 7H5',4,3)
于 2013-06-17T20:51:08.173 回答
1

对于单个空格,您可以使用POSITION()SUBSTRING()。您必须偏移POSITION()函数返回的空白位置。

   WITH CTE(FieldName) AS
    (SELECT 'TB7 TCH' AS FieldName)
    SELECT SUBSTRING(FieldName FROM 1 FOR (POSITION(' ' IN FieldName) - 1)) 
            || SUBSTRING(FieldName FROM (POSITION(' ' IN FieldName) + 1))
    FROM CTE;
于 2013-06-17T20:58:40.797 回答
0

尝试使用 substr(); 例如:4 = 从位置 4 开始 && 1 = 删除一个字符。

   substr(Table1.fieldname, 4,1) 
于 2013-06-17T20:42:37.497 回答