我正在尝试在链接中分离出一个参数,即utm_content = using SQL。
在域名结束后,utm内容总是直接落在?在&amp ;.之前这是我到目前为止所提出的,但我收到了一个错误。
我为要删除的数据创建了3列(因为我没有成功分离utm内容),称为Domain,utmcontent和tracking。
有人可以帮忙吗?
谢谢!
SELECT
CASE
WHEN Charindex(':',LastLinkClicked) > 0 THEN
Substring(LastLinkClicked,1,Charindex(':', LastLinkClicked)-1)
ELSE LastLinkClicked
END AS Domain ,
CASE
WHEN Charindex('?',LastLinkClicked) > 0 THEN
CASE
WHEN Charindex('?', Substring(LastLinkClicked,Charindex('?',LastLinkClicked)+1,Len(LastLinkClicked))) > 0 THEN Substring(Substring(LastLinkClicked,Charindex('?',LastLinkClicked)+1,Len(LastLinkClicked)),1, Charindex('?', Substring(LastLinkClicked,Charindex('?',LastLinkClicked)+1,Len(LastLinkClicked)))-1 )
ELSE Substring(lastlinkclicked,Charindex('?',linkname)+1,Len(linkname))
END as utmcontent ,
CASE
WHEN charindex('&',LastLinkClicked) > 0 THEN
CASE
WHEN charindex('&', substring(LastLinkClicked,charindex('&',LastLinkClicked)+1,len(LastLinkClicked))) > 0 THEN substring(substring(LastLinkClicked,charindex('&',LastLinkClicked)+1,len(LastLinkClicked)),1, charindex('&', substring(LastLinkClicked,charindex('&',LastLinkClicked)+1,len(LastLinkClicked)))-1 )
ELSE substring(LastLinkClicked,charindex('&',LastLinkClicked)+1,len(LastLinkClicked))
END AS tracking
答案 0 :(得分:0)
看起来你的小写'as'可能是错的。试试
SELECT
CASE
WHEN Charindex(':',LastLinkClicked) > 0 THEN
Substring(LastLinkClicked,1,Charindex(':', LastLinkClicked)-1)
ELSE LastLinkClicked
END AS Domain ,
CASE
WHEN Charindex('?',LastLinkClicked) > 0 THEN
CASE
WHEN Charindex('?', Substring(LastLinkClicked,Charindex('?',LastLinkClicked)+1,Len(LastLinkClicked))) > 0 THEN Substring(Substring(LastLinkClicked,Charindex('?',LastLinkClicked)+1,Len(LastLinkClicked)),1, Charindex('?', Substring(LastLinkClicked,Charindex('?',LastLinkClicked)+1,Len(LastLinkClicked)))-1 )
ELSE Substring(lastlinkclicked,Charindex('?',linkname)+1,Len(linkname))
END AS utmcontent ,
CASE
WHEN charindex('&',LastLinkClicked) > 0 THEN
CASE
WHEN charindex('&', substring(LastLinkClicked,charindex('&',LastLinkClicked)+1,len(LastLinkClicked))) > 0 THEN substring(substring(LastLinkClicked,charindex('&',LastLinkClicked)+1,len(LastLinkClicked)),1, charindex('&', substring(LastLinkClicked,charindex('&',LastLinkClicked)+1,len(LastLinkClicked)))-1 )
ELSE substring(LastLinkClicked,charindex('&',LastLinkClicked)+1,len(LastLinkClicked))
END AS tracking