Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using dbo.split method in sql server to pass values to stored procedure as input parameter but it is giving wrong output 


My query is as
select * from Fin where Company in (select Company  from  dbo.Split('GHCL LTD,GODREJ INDUSTRIES LTD',','))


where
'GHCL LTD,GODREJ INDUSTRIES LTD'
are company names.

but it giving datafrom all company present in database

What I have tried:

select * from Fin where Company in (select Company  from  dbo.Split('GHCL LTD,GODREJ INDUSTRIES LTD',','))
Posted
Updated 19-Jan-18 5:09am

Its better go for
GetColumnValue
function in sql.

Split function by comma in SQL Server 2008 - Stack Overflow[^]

A suggestion for you is that please don't post questions with organization names instead please add X,Y Z like this.
 
Share this answer
 
v2
check my Tip, it might help you
How to Query Comma Separated Value Column in SQL[^]
 
Share this answer
 
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:
SQL
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:
SQL
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900