Turning a Comma Separated string into individual r

2019-09-23 10:13发布

I read the post: Turning a Comma Separated string into individual rows

And really like the solution:

SELECT A.OtherID,  
     Split.a.value('.', 'VARCHAR(100)') AS Data  
 FROM  
 (     SELECT OtherID,  
         CAST ('<M>' + REPLACE(Data, ',', '</M><M>') + '</M>' AS XML) AS Data  
     FROM  Table1
 ) AS A CROSS APPLY Data.nodes ('/M') AS Split(a); 

But it did not work when I tried to apply the method in Teradata for a similar question. Here is the summarized error code: select failed 3707: expected something between '.' and the 'value' keyword. So is the code only valid in SQL Server? Would anyone help me to make it work in Teradata or SAS SQL? Your help will be really appreciated!

1条回答
对你真心纯属浪费
2楼-- · 2019-09-23 10:44

This is SQL Server syntax.

In Teradata there's a table UDF named STRTOK_SPLIT_TO_TABLE, e.g.

SELECT * FROM dbc.DatabasesV AS db
JOIN 
 (
   SELECT token AS DatabaseName, tokennum
   FROM TABLE (STRTOK_SPLIT_TO_TABLE(1, 'dbc,systemfe', ',')
        RETURNS (outkey INTEGER,
                 tokennum INTEGER,
                 token VARCHAR(128) CHARACTER SET UNICODE)
              ) AS d 
 ) AS dt
ON db.DatabaseName  = dt.DatabaseName
ORDER BY tokennum;

Or see my answer to this similar question

查看更多
登录 后发表回答