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.
Author |
Topic |
ilimax
Posting Yak Master
164 Posts |
Posted - 2008-06-13 : 16:10:41
|
I have never used FUNCTION in Transact SQL. I see RETURN statement in this example below and for me looks same as OUTPUT parameter in STORED PROCEDURE. I found in BOOKS ONLINE, I can execute FUNCTION same as STORED PROCEDURE. I have never tried to execute from my VB applications, but I will try.Can anybody tell me where is the best place to use CREATE FUNCTION?CREATE FUNCTION fnFirstName (@FullName VarChar(100) , @FirstOrLast VarChar(5)) RETURNS VarChar(100)ASBEGIN DECLARE @CommaPosition Int DECLARE @TheName VarChar(100) IF @FirstOrLast = 'First' BEGIN SET @CommaPosition = CHARINDEX(',', @FullName) SET @TheName = SUBSTRING(@FullName, @CommaPosition + 2, LEN(@FullName)) END ELSE IF @FirstOrLast = 'Last' BEGIN SET @CommaPosition = CHARINDEX(',', @FullName) SET @TheName = SUBSTRING(@FullName, 1, @CommaPosition - 1) END RETURN @TheName ENDGO |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-06-13 : 16:14:48
|
You can't execute a function in the same way as a stored procedure. Functions get used in queries, like this:--scalar-valuedSELECT dbo.SomeFunction(Column1)FROM Table1--table-valuedSELECT * FROM dbo.SomeOtherFunction(@var1)Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
|
|