At a guess, your custom
dbo.Split
function doesn't return a column called
Company
.
Which means that the
Company
column within your inner query is actually a reference to the
Company
column from your outer query.
Making your query equivalent to:
select * from Fin where Company = Company
That will return all records where the
Company
column is not
NULL
.
Find out the name of the column returned from your
dbo.Split
function, and use that:
select * from Fin where Company in (select Value from dbo.Split('GHCL LTD,GODREJ INDUSTRIES LTD', ','))
NB: If you're using SQL 2016 or higher, you can use the built-in
STRING_SPLIT[
^] function, which returns a single column called
value
.