3. September 2016 15:07
Sometimes I forget how to do simple things, like splitting a string into sections based on a delimiter.
Here's a nice way to test your code on a range of input values, and see the interim results, in one hit:
myobject as (
-- put in a range of test values:
select 'dbo.MyFunction' as NAME
more2 as (
-- calculate interesting attributes:
len( NAME ) as LENGTH_,
charindex( '.', NAME ) as POSITION
-- perform the test:
NAME, POSITION, LENGTH_,
case when POSITION=0 then 'dbo'
else substring( NAME, 1, POSITION-1 )
end as SCHEMA_,
substring( NAME, POSITION+1 , (LENGTH_ - POSITION ) ) as OBJECT_