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
 SQL Server Development (2000)
 Functions

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-07-03 : 07:41:47
Chari writes "Could some one explain when I can best use functions.
Other than use of Repetetive sql statements any thing else?
Appreciated.
Chari"

X002548
Not Just a Number

15586 Posts

Posted - 2003-07-03 : 10:59:32
What better use?

Also SQL Server does not come with a rich supply of mathematical function, but you could build more...

Also you could build on the charachter parsing function

For example you could create a function like:


CREATE FUNCTION udf_WORDS
(@str varchar(8000))
RETURNS int
AS
BEGIN
DECLARE @Words INT, @Pos INT, @x Int
SELECT @Words = 0, @Pos = 1, @x = -1

WHILE (@x <> 0)
BEGIN
SET @x = CHARINDEX(' ', @str, @Pos)
SET @Pos = @x + 1
SET @Words = @Words + 1
END

RETURN @Words
END


This identifies how many words are in a string (delimited by a space).



Brett

8-)
Go to Top of Page
   

- Advertisement -