Re: User defined function problem

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: babz (babz_at_discussions.microsoft.com)
Date: 10/26/04


Date: Mon, 25 Oct 2004 22:43:02 -0700

Thanx a lot friends

"Narayana Vyas Kondreddi" wrote:

> It will work fine, if you call the function as shown below:
>
> Select * from dbo.udfSelSplittedCodes1('1,2,3', default, default)
>
> This is documented in the CREATE FUNCTION page of Books Online.
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/
>
>
> "babz" <babz@discussions.microsoft.com> wrote in message
> news:66467612-25F2-4D5D-ABE9-87AFC869D827@microsoft.com...
> I am using a function to split the delimited separated codes,
>
> CREATE FUNCTION dbo.udfSelSplittedCodes1
>
> ( @CdString VARCHAR(8000)
> , @RowDelimiter CHAR(1) = ','
> , @ColDelimiter CHAR(1) = ':'
> )
> RETURNS @tblCodes TABLE (Cd INT)
> AS
> BEGIN
>
>
> DECLARE @RetVal int
> ,@ErrMsg varchar(255)
> ,@SPRetVal int
>
> DECLARE @error int /* Error Code */
>
>
> WHILE CharIndex(@RowDelimiter, @CdString) > 1
> BEGIN
> INSERT INTO @tblCodes (Cd)
> VALUES (SubString(@CdString, 1, CharIndex(@RowDelimiter, @CdString)-1))
> SELECT @CdString = SubString(@CdString, CharIndex(@RowDelimiter,
> @CdString)+ 1 , Len(@CdString))
> SELECT @Error = @@Error
>
> END
> INSERT INTO @tblCodes (Cd)
> VALUES (@CdString)
> SELECT @Error = @@Error
>
> Return
>
>
> END
>
> It is working fine if i am passing all the paramters.
>
> Select * from dbo.udfSelSplittedCodes1('1,2,3', ',', ':')
>
> but if i ignored the second and third param in my query
>
> Select * from dbo.udfSelSplittedCodes1('1,2,3')
>
> it is giving me 'insufficient number of arguments supplied error'.
>
> In my function i have given default values for second and third params
>
> And more over how to raiseerror in function.
>
>
>
>
>
>
>
>
>
>
>
>



Relevant Pages

  • Re: em displays binary data
    ... Vyas, MVP (SQL Server) ... > Vyas, MVP ... > "Narayana Vyas Kondreddi" wrote: ... >> the actual data displaying, ...
    (microsoft.public.sqlserver.server)
  • Re: Will databases still work if they are moved to a new server?
    ... Is SP3+ the same thing as SP3a? ... Bing ... "Narayana Vyas Kondreddi" wrote: ... > But then there are situations like moving to W2K3, where SQL Server is ...
    (microsoft.public.sqlserver.server)
  • Re: Unable to post notification to SQLServerAgent
    ... Narayana Vyas Kondreddi wrote: ... > the system drive or the sql server installation drive is running out ... >> command') ... >> Any suggestion? ...
    (microsoft.public.sqlserver.odbc)
  • Re: Enterprise Manager Error
    ... It gives error Microsoft Management Console has encountered a problem and ... This happens to only Sql Server 2000 Enterprise Manager, ... registry and if I do fresh installation then also same error. ... "Narayana Vyas Kondreddi" wrote: ...
    (microsoft.public.sqlserver.setup)