Stored Prod VS User Defined Function (1 Viewer)

accessman2

Registered User.
Local time
Today, 07:57
Joined
Sep 15, 2005
Messages
335
Stored procedures are different from functions in that they do not return values in place of their names and they cannot be used directly in an expression.

I found this statement in the book online. Does that means that only User Defined Function can return the results, whereas Stored Procedure cannot do that. And, User Defined Function can be applied inside the statement, such as select tbl1.field0, function(1,2) from tbl1.......
whereas Stored Procedure cannot do that, it's only allowed to execute one statement, such as Exec Prod1. ...

Is that correct?
 

SQL_Hell

SQL Server DBA
Local time
Today, 15:57
Joined
Dec 4, 2003
Messages
1,360
Yes thats correct, but you should only be using User defined functions for a scenario like formatting data, for example if you wanted a function to change an English date to an american date then you would create a function for doing it that can be used within a sql statement. Use stored procedures for inserts/updates/deletes/complicated sql stuff.
 

pdx_man

Just trying to help
Local time
Today, 07:57
Joined
Jan 23, 2001
Messages
1,347
Also know that you can have table functions, too.

Select *
FROM fn_YourFunction('08/21/2007')
 

Users who are viewing this thread

Top Bottom