The following code could be incorporated into a stored procedure, user defined function, or an inline table valued function.
declare @input varchar(max)
declare @count int
set @count = 5
set @input = 'The skilful blending of drawn animation and computer-generated imagery excited anime fans when this science fiction mystery was released in 1995'
set @input = @input+' '
-- this is the actual code, @input and @count would be passed as parameters
;with tally (N) as
(select row_number() over(order by (select null)) from master.sys.all_columns)
,Array AS
(select Row_Number() over (order by N) as X, N
from tally
where substring(@input,N,1) = ' '
)
select X as Words, left(@input,N-1) as sub_string from Array
where X = @count
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills