· 8 years ago · Mar 01, 2018, 10:08 AM
1CREATE FUNCTION dbo.Splitfn(@String varchar(8000), @Delimiter char(1))
2returns @temptable TABLE (items varchar(8000))
3 as
4begin
5declare @idx int
6declare @slice varchar(8000)
7
8select @idx = 1
9 if len(@String)<1 or @String is null return
10
11while @idx!= 0
12begin
13 set @idx = charindex(@Delimiter,@String)
14 if @idx!=0
15 set @slice = left(@String,@idx - 1)
16 else
17 set @slice = @String
18
19 if(len(@slice)>0)
20 insert into @temptable(Items) values(@slice)
21
22 set @String = right(@String,len(@String) - @idx)
23 if len(@String) = 0 break
24end
25return
26
27end
28
29ALTER PROCEDURE [dbo].[Employees_Delete]
30-- Add the parameters for the stored procedure here
31@Id varchar(50)
32AS
33BEGIN
34-- SET NOCOUNT ON added to prevent extra result sets from
35-- interfering with SELECT statements.
36SET NOCOUNT ON;
37
38-- Insert statements for procedure here
39
40 if exists( select Emp_Id from Employee where Emp_Id=dbo.Splitfn(@Id,','))
41begin
42 update Employee set Is_Deleted=1 where Emp_Id=dbo.Splitfn(@Id,',')
43 select 'deleted' as message
44end
45END
46
47Cannot find either column "dbo" or the user-defined
48function or aggregate "dbo.Splitfn", or the name is ambiguous.
49
50where Emp_Id IN (SELECT i.items FROM dbo.Splitfn(@Id,',') AS i)
51
52select Emp_Id
53from Employee E JOIN dbo.Splitfn(@Id,',') CSV ON E.Emp_Id = CSV.items
54
55select * from [dbo].[SplitString]('1,2',',') -- Will work
56
57select [dbo].[SplitString]('1,2',',') -- will not work and throws this error