Discussion:
Problem with using a field parameter, in a user defined function
(too old to reply)
Dan Campbell
2017-07-06 15:14:10 UTC
Permalink
Hi,


I’m using a function defined at

-- https://www.codeproject.com/Tips/798671/Split-string-into-Rows-Columns-using-Delimiters

for a 2008 function, but can’t figure out how to make it work with varchar field parameters. It works fine with simple strings.


So e.g.,


Select * from dbo.SplitDelimitedString('20|21/06/13#15|19/06/13#15|14/06/13','#')

Works fine.


But

This

USE mydatabase ;
SELECT dbo.SplitDelimitedString(myfield,'|') FROM mytable ;


Returns

Cannot find either column "dbo" or the user-defined function or aggregate
"dbo.SplitDelimitedField", or the name is ambiguous.


I’ve tried different combinations of prefixes, and almost always get the same result.


I also tried something I didn't expect to work, just for the heck of it,


SELECT * FROM SplitDelimitedString(mytable.pdLine,'|') ;


, and get the error



Incorrect syntax near '.'.



How do we send SplitDelimitedString() a field name from a table?
Dan Campbell
2017-07-06 17:50:09 UTC
Permalink
Post by Dan Campbell
Hi,
I’m using a function defined at
-- https://www.codeproject.com/Tips/798671/Split-string-into-Rows-Columns-using-Delimiters
for a 2008 function, but can’t figure out how to make it work with varchar field parameters. It works fine with simple strings.
So e.g.,
Select * from dbo.SplitDelimitedString('20|21/06/13#15|19/06/13#15|14/06/13','#')
Works fine.
But
This
USE mydatabase ;
SELECT dbo.SplitDelimitedString(myfield,'|') FROM mytable ;
Returns
Cannot find either column "dbo" or the user-defined function or aggregate
"dbo.SplitDelimitedField", or the name is ambiguous.
I’ve tried different combinations of prefixes, and almost always get the same result.
I also tried something I didn't expect to work, just for the heck of it,
SELECT * FROM SplitDelimitedString(mytable.pdLine,'|') ;
, and get the error
Incorrect syntax near '.'.
How do we send SplitDelimitedString() a field name from a table?
The answer: It was necessary to use CROSS APPLY, in the query.

Loading...