Is there some magic to user-defined functions that I'm not understanding? I have created the following function:
As I understand it, that should create a function that I can use at anytime in the DB. The code within the function works.
Now, how do I execute this function??
What I really want to do is have the following run from a SQL statement:
I would be executing the SQL file from a batch script using osql (batch script is coded and works already). I don't know very much when it comes to SQL =(
The real goal is to have @sym be assigned to a passable argument, so that I can run my script automatically, instead of having to strip the code out of a function and running it 300+ times to add all of our problem categories.
Code:
-- contents of sql file to create function
CREATE FUNCTION fx_createProblemCategoryTest3
(@problemCategory nvarchar(128))
RETURNS nvarchar(128)
AS
BEGIN
declare @sym as nvarchar(128);
-- This is the argument we pass
set @sym=@problemCategory;
-------------------------------
-- work some magic... I've tested all the middle stuff and it works!
insert into prob_ctg (sym, id, persid)
values (@sym, @id, @persid);
return @sym
END
Now, how do I execute this function??
What I really want to do is have the following run from a SQL statement:
Code:
-- contents of runMe.sql
fx_createProblemCategoryTest3('Cat1');
fx_createProblemCategoryTest3('Cat2');
fx_createProblemCategoryTest3('Cat3');
...
fx_CreateProblemCategoryTest3('Cat300');
I would be executing the SQL file from a batch script using osql (batch script is coded and works already). I don't know very much when it comes to SQL =(
The real goal is to have @sym be assigned to a passable argument, so that I can run my script automatically, instead of having to strip the code out of a function and running it 300+ times to add all of our problem categories.