|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, October 18, 2012 12:50 AM
Points: 174,
Visits: 315
|
|
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 INFOSYS Limited Quality is not an act, it is a habit.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, April 04, 2008 2:22 AM
Points: 1,
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
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 5:38 AM
Points: 870,
Visits: 858
|
|
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
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 5:38 AM
Points: 870,
Visits: 858
|
|
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
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 1:09 PM
Points: 13,383,
Visits: 25,187
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, October 18, 2012 12:50 AM
Points: 174,
Visits: 315
|
|
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 INFOSYS Limited Quality is not an act, it is a habit.
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 1:09 PM
Points: 13,383,
Visits: 25,187
|
|
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 2012 Query Performance Tuning SQL Server 2008 Query Performance Tuning Distilled and SQL Server Execution Plans
Product Evangelist for Red Gate Software
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, October 18, 2012 12:50 AM
Points: 174,
Visits: 315
|
|
Thanks a lot. The post was really helpful. 'll surely keep those points in mind.
Chandrachurh Ghosh DBA – MS SQL Server INFOSYS Limited Quality is not an act, it is a habit.
|
|
|
|