February 26, 2008 at 9:30 pm
hi, all
i am trying to make a function in which i want to pass a coloumn and a table .
these columnn and table will be used inside the function body.
so i want to know how can i pass a column and a table as a paramerer in creating a function or a stored procedure . what are the datatypes which can be used for this???
i am new to sql server so plz be simple in language so that i can understand it better..
thanx
hv fun 🙂
February 26, 2008 at 9:44 pm
Use datatype SYSNAME.
February 26, 2008 at 9:55 pm
i have used sysname but it still not working
can u give me the syntax
i have used like below :
CREATE FUNCTION fun_name (@column_name sysname , @table_name sysname)
RETURNS sysname
BEGIN
RETURN (SELECT @column_name FROM @table_name)
END
how should i pass the parameter while calling the function ???
thanx 4 the reply
February 27, 2008 at 1:22 am
You can't have dynamic SQL in a function.
http://www.sommarskog.se/dynamic_sql.html
N 56°04'39.16"
E 12°55'05.25"
February 27, 2008 at 2:22 am
I think perhaps you've missed something here. You write a subroutine (stored procedure, function, view, etc) in SQL to interact with a specific set of tables. Passing table names around often indicates some lack of understanding or inappropriate database design. Could you please indicate what you're trying to achieve (apart from the obvious which is retrieve some data from a random column in a random table) and we may be able to guide you to avoid the function altogether.
February 27, 2008 at 3:46 am
thanx 4 asking more 🙂
actually i am new to sql server so i am trying to go through all aspects of that.
i was trying to make a function which can perform addition operation on all the data of a given column of a given table .......... i know there is a built-in function 4 that i.e SUM but i was trying to make my own function .
so create that function i need column and table as a variable.
i can make a stored procedure but i am not able to create a function 4 the same
thanx 🙂
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply