HomeForum
Welcome, Guest

User Defined Function in Visual Importer Pro
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: User Defined Function in Visual Importer Pro

User Defined Function in Visual Importer Pro 4 years, 6 months ago #474

I have SQL code which includes a UDF that works well outside of VIP. However I can't get it to work within the program, either as a script or "SQL After" on the import.

I get the error " Invalid object name 'dbo.fnSplit_Name' ".

Does VIP support UDF's and if so is there some special format I need to follow?

Thanks

RE: User Defined Function in Visual Importer Pro 4 years, 6 months ago #475

  • mike8888
  • OFFLINE
  • Expert Boarder
  • Posts: 131
  • Karma: 0
Hello

May be you need to specify a database name?

EG
[mydatabase].[dbo].[myfunction]

Peter

RE: User Defined Function in Visual Importer Pro 4 years, 6 months ago #476

Thanks Peter, butI'm not clear what Db would apply. The User Function doesn't apply to any specific Db as it can be called from anywhere. It passes the parameter to the function and returns a row of columns with the results.

I've tried it with a smaller test UDF (below) and also found it works with othe SQL Query Editors but not with your Database Browser (nor VIP).

Any other thoughts?

Thanks

Joe

============================================
/* Function is to split a delimited filed into a number of table items.
Delimiter can be any value including space.

The process is implemented as a a function.

The benefits of this method are that it doesn't use tempdb (so it won't be affected by anything that may lock tempdb), it is slightly faster, and you can use the function just like any other table -- for example, select c.* from customers c where c.city in (select item from fnSplit('Dallas,New York,Chicago',',') )

To test, use of of these where the second item is the delimiter:
select * from fnSplit('1,22,333,444,,5555,666', ',')
select * from fnSplit('1##22#333##444','##') --note second item has embedded #
select * from fnSplit('1 22 333 444 5555 666', ' ')


*/
CREATE FUNCTION dbo.fnSplit(
@sInputList VARCHAR(8000) -- List of delimited items
, @sDelimiter VARCHAR(8000) = ',' -- delimiter that separates items
) RETURNS @List TABLE (item VARCHAR(8000))

BEGIN
DECLARE @sItem VARCHAR(8000)
WHILE CHARINDEX(@sDelimiter,@sInputList,0) <> 0
BEGIN
SELECT
@sItem=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@sDelimiter,@sInputList,0)-1))),
@sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@sDelimiter,@sInputList,0)+LEN(@sDelimiter),LEN(@sInputList))))

IF LEN(@sItem) > 0
INSERT INTO @List SELECT @sItem
END

IF LEN(@sInputList) > 0
INSERT INTO @List SELECT @sInputList -- Put the last item in
RETURN
END
GO

RE: User Defined Function in Visual Importer Pro 4 years, 6 months ago #477

  • mike8888
  • OFFLINE
  • Expert Boarder
  • Posts: 131
  • Karma: 0
Joe

The Database you created your fuction in.

I have got a database called DEMO.
I run a script you posted
Than I run select * from fnSplit('1,22,333,444,,5555,666', ',') in Data Browser and I got results

When I did use master and run select again it failed.

Peter
  • Page:
  • 1
Time to create page: 0.17 seconds

Testimonials

"Using Active Table Editor is the easiest way of editing lookup tables  I've ever seen. A free 30-day trial is available on their Web site; the only issue is that when the 30 days are up, you're going to want to buy it."
- Moo Ling, Software Enginier

User Login

You only need to log in or register to use our support forum



Our customers

BP

BBC

HSBC


Databases we work with

Go to top