Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Calling a User Defined function in a view

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-03-30 : 06:07:20
Hi Am using a view to call as user Define Function, here is how am calling the function.

dbo.udf_Voy_Serv_ind ('Serv_Prod_ind','Solve_ind','Part_ind','Field_ind')

Each of the Variables in the function are Alias of other functions, in the view, so am not using column name in a table, am just wondering is this correct in the way am calling the function as it does not seem to bring back the results i get what i do a select on the function in query Analyzer

Here is a example of how i call the other functions as you'll see am using the table dbo.name.col_name
dbo.udf_Voy_Serv_Prod_ind(dbo.Test_V_RCA.Serviceable, dbo.Test_V_RCA.ContractDesc, dbo.Test_V_RCA.RCAAvailable)


Just a quick update, i've created another view and added in the view i was working on so now i've got the columns that were perviously Alias in my last view and i can call my function using them, but i'd still like to get it working the other way.

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-03-30 : 09:03:37
Views calling functions calling views using aliases....

Huh?

Ever heard of the K.I.S.S. principle?
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-03-30 : 09:14:38
Yes i would not like to do this "Views calling functions calling views using aliases...." i want my function to use the Alias of the other functions thats in my view..
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-03-30 : 10:08:30
Huh? Huh?

Post your code.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-03-30 : 13:43:14
Programming is a funny thing ....

In most industries, beginners work on simple, short projects and only use the most basic concepts that they have learned. The veterans, meanwhile, work on things that are very large, complicated, difficult to manage, and require lots of time, energy and resources.

Yet, in programming, beginners overcomplicate things and end up creating large, complicated, unmanageable projects that require lots of resources, without any application of the most basic concepts. A veteran programmer, meanwhile, uses those basic concepts to write very short, compact, and easy to manage code.
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-03-30 : 14:36:18
SQL is not really like other programming languages where you can write a whole program in the arguments.

______________________
why? Because I can.

rockmoose
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-03-31 : 03:36:55
What am doing is not very complicated in fact its very simple.

I have 4 functions which i call in a view to return either 1 or 0
Here is a example of how i call the functions as you'll see am using the tables that i added into the view Example (dbo.name.col_name)
dbo.udf_Voy_Serv_Prod_ind(dbo.Test_V_RCA.Serviceable, dbo.Test_V_RCA.ContractDesc, dbo.Test_V_RCA.RCAAvailable)

Now for each of my 4 functions i give them a Alias, let say they are called A1, A2, A3, A4

Now i wrire another function that uses the values from the pervious 4 functions, so i need to add A1, A2, A3, A4 as the variables in the function to call it here is how i "think" i should call them

dbo.udf_Voy_Serv_ind ('A1','A2','A3','A4')

But this function does not work correctly as when i test it by putting in values in query Analyzer like

Select dbo.udf_Voy_Serv_ind ('1','1','1','0')

It should return 1 as an example.

I think its becuase am calling Alias names (A1, A2 etc..)in my function and not actually Columns name in a table that causing the error.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-03-31 : 09:24:14
quote:
Originally posted by rookie_sqlNow i wrire another function that uses the values from the pervious 4 functions, so i need to add A1, A2, A3, A4 as the variables in the function to call it here is how i "think" i should call them

dbo.udf_Voy_Serv_ind ('A1','A2','A3','A4')

But this function does not work correctly as when i test it by putting in values in query Analyzer like

Select dbo.udf_Voy_Serv_ind ('1','1','1','0')

It should return 1 as an example.

I think its becuase am calling Alias names (A1, A2 etc..)in my function and not actually Columns name in a table that causing the error.


It's because you are passing these parameters as strings. Now, your second example may work because SQL Server can implicitly convert the character string '1' to the numeric value 1, but when you pass 'A1', it hasn't a clue what that represents.

Assign the results of your function calls to variables named, for example, @A1. Then you can pass these variable values as your parameters.
Go to Top of Page
   

- Advertisement -