SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Function not returning any value


SQL Function not returning any value

Author
Message
Chandrachurh Ghosh
Chandrachurh Ghosh
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1563 Visits: 331
Hi guys,
I have a bit of problem here.
My SQL Server function is not returning any value. There seems to be any configuration problem.

Below is my script. Please help. Thanks in advance.



/****** Object: UserDefinedFunction [dbo].[fnReplaceNonPrintCharsFortxtOnly] Script Date: 04/03/2008 12:21:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author : Sandeep Sahu
-- Create date : 01-April-2008
-- Description : To Replace the Non Print characters with some strings and
-- remove all html tags after replacement
-- Revision History : New Creation
-- =============================================
create FUNCTION [dbo].[fnReplaceNonPrintCharsFortxtOnly]
-- exec fnReplaceNonPrintCharsFortxtOnly ' '
(
@Text AS VARCHAR(8000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @return AS VARCHAR(8000)
DECLARE @StartPos AS INT
DECLARE @EndPos AS INT
DECLARE @LenStr AS INT
DECLARE @inttmpId AS INT
DECLARE @strToReplace AS VARCHAR(8000)
DECLARE @strToReplaceTxtOnly AS VARCHAR(8000)

DECLARE ReplaceNonPrintChr_txtOnly CURSOR FAST_FORWARD FOR
SELECT ReplaceNonPrintCharID,String_To_Replace,String_To_Replace_in_txtOnly
FROM LKP_ReplaceNonPrintCharacter
WHERE IsDeleted = 0
OPEN ReplaceNonPrintChr_txtOnly

FETCH NEXT FROM ReplaceNonPrintChr_txtOnly
INTO @inttmpId,@strToReplace,@strToReplaceTxtOnly

WHILE @@FETCH_STATUS = 0
BEGIN
IF(@strToReplace <> '')
BEGIN
IF(@strToReplaceTxtOnly <> '' AND @strToReplaceTxtOnly <> 'Empty String')
BEGIN
SET @Text = REPLACE(@Text,@strToReplace,@strToReplaceTxtOnly)
END
ELSE IF(@strToReplaceTxtOnly = 'Empty String')
BEGIN
SET @Text = REPLACE(@Text,@strToReplace,'')
END
END
FETCH NEXT FROM ReplaceNonPrintChr_txtOnly INTO @inttmpId,@strToReplace,@strToReplaceTxtOnly
END -- end of cursor begin statement

CLOSE ReplaceNonPrintChr_txtOnly
DEALLOCATE ReplaceNonPrintChr_txtOnly


-- To Remove all HTML Tags after the above replacement is done
SET @StartPos = CHARINDEX('<', @Text)
SET @EndPos = CHARINDEX('>', @Text, CHARINDEX('<', @Text))

SET @LenStr = (@EndPos - @StartPos) + 1
WHILE (@StartPos > 0 AND @EndPos > 0 AND @LenStr > 0)
BEGIN
SET @Text = STUFF(@Text, @StartPos, @LenStr, '')
SET @StartPos = CHARINDEX('<', @Text)
SET @EndPos = CHARINDEX('>', @Text, CHARINDEX('<', @Text))
SET @LenStr = (@EndPos - @StartPos) + 1
END
SET @return = @Text
RETURN @return
END


Even the following script does not work.....

CREATE FUNCTION [dbo].[FNTest]
()
RETURNS VARCHAR(20)
AS
BEGIN
RETURN 'RR'

END

It seems none of the functions are working...

Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
saratheamit2006
saratheamit2006
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 1
Hi to all
can anybody tell me how can i create new user login in sql server 2005 for my database?
Thanks in advance
SQLZ
SQLZ
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6158 Visits: 940
Seeing as none of your functions are working let's look at the small test function you created. What do you get when you run:

select dbo.FNTest()



Karl
source control for SQL Server
SQLZ
SQLZ
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6158 Visits: 940
saratheamit2006 (4/3/2008)
Hi to all
can anybody tell me how can i create new user login in sql server 2005 for my database?
Thanks in advance


You should start a new post rather than post your question in response to someone elses question.

But to answer your question, have a look at the CREATE LOGIN statement in books online. There are various examples in there on how to create a new login in SQL 2005.

Karl
source control for SQL Server
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)

Group: General Forum Members
Points: 198850 Visits: 33389
What error are you getting? Your test function ran fine on my machine.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Chandrachurh Ghosh
Chandrachurh Ghosh
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1563 Visits: 331
I am extremely sorry for this. I had done a EXEC
They are working fine. It happens you know, when in tight situation, getting the basic stuff wrong.

Anyway, as the point has come, what is the difference between a function and a stored procedure. Is it only compilation?

Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)

Group: General Forum Members
Points: 198850 Visits: 33389
Much more than compilation. Functions come in two basic flavors, table valued & scalar valued. Scalar is used for a calculation, table valued are sort of like parameterized views. Only problem is, the scalar valued functions, when used in queries, can almost make the query go from a nice set based function to a RBAR (row-by-agonizing-row) function. And the table valued functions, when used in a single statement are usually fine, but when used with multi-statements, since they don't have statistics associated and the optimizer can't really generate plans for them, it assumes that the function is returning 1 (one) row and makes it's decisions from that fact. No big deal when returning a small number of rows, but a HUGE deal when returning larger numbers of rows.

Stored procedures are utterly different critters. I'd suggest hitting the Books Online & reading up on both to get more details. Then come back & read through the articles & posts to see the good uses functions can provide and the problems they can create.

Just as an example, we had a development team that saw how the functions worked and decided that they made the perfect sort of transition between object oriented code and database access. So they wrote queries that joined functions to functions and those functions called functions that joined between functions which called to ther functions,etc. It all appeared very elegant. Since all the execution plans were based on a single row of data, and the developers, while developing only ever used a single row of data for testing their code, everything worked fine. Then, after development & qa, we were getting ready for the production release and more extensive testing with production level data started. We got blocks, deadlocks, timeouts... It was a horrifying nightmare. We had to rewrite the entire data access layer into regular old SELECT statements inside stored procedures, not fun.

Be VERY careful about the use of functions.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Chandrachurh Ghosh
Chandrachurh Ghosh
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1563 Visits: 331
Thanks a lot. The post was really helpful. 'll surely keep those points in mind.

Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search