[英]How to specify column names in cross apply join in SQL Server
I want to know how do we mention column name in Cross Apply Join and specify table name 我想知道我们如何在“交叉应用联接”中提及列名并指定表名
Already Working Query: 已经工作的查询:
select v.*, left(v.dir, charindex('/', v.dir) - 1) as dirname
from (values ('/Directory_A/Directory_B/Directory_C/Folder1/Folder2') ) t(path) cross apply
(values (stuff(t.path, 1, len(t.path) - charindex(reverse('Directory_'), reverse(t.path)) + 1, ''))) v(dir)
Expected Query: 预期查询:
select v.*, left(v.dir, charindex('/', v.dir) - 1) as dirname
from (values (“ColumnName”) ) t(path) cross apply
(values (stuff(t.path, 1, len(t.path) - charindex(reverse('Directory_'), reverse(t.path)) + 1, ''))) v(dir) from table name
It's will work for you 它会为你工作
DECLARE @path VARCHAR(100)='/Directory_A/Directory_B/Directory_C/Folder1/Folder2'
SELECT SUBSTRING( @path,LEN(@path)-LEN(SUBSTRING(@path,PATINDEX('%folder%',@path), 100))-1, 1)
I think you just need the table reference: 我认为您只需要表引用:
select v.*, left(v.dir, charindex('/', v.dir) - 1) as dirname
from <tablename> tab cross apply
(values (tab.ColumnName) ) t(path) cross apply
(values (stuff(t.path, 1, len(t.path) - charindex(reverse('Directory_'), reverse(t.path)) + 1, ''))) v(dir) from table name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.