4 ms·
Cool I didn't know about PARSENAME. I've always written udfs for that. I suppose it wouldn't work in all cases since it can only split on '.', but with REPLACE
by infogulch 10y ago
Cool I didn't know about PARSENAME. I've always written udfs for that. I suppose it wouldn't work in all cases since it can only split on '.', but with REPLACE it gets you a long ways.
Edit: Looks like PARSENAME is more exciting than that. It actually unescapes escaped identifiers:
select n, parsename('[srv with
newline].[db [ with ]] brackets].[schema with . dot]."quoted . dot"', n)
from (values (1),(2),(3),(4),(5)) n(n)
/* results:
1 quoted . dot
2 schema with . dot
3 db [ with ] brackets
4 srv with
newline
5 NULL
*/
Another fun fact about SQL Server: Object identifiers support newlines, among other crazy characters. Don't believe me?
create table #t ([newline
here] int)
select * from #t
Stay safe, and always use QUOTENAME [1]. :D
[1]: https://docs.microsoft.com/en-us/sql/t-sql/functions/quotename-transact-sql https://docs.microsoft.com/en-us/sql/t-sql/functions/quotena...