Home All Groups Group Topic Archive Search About

User-defined function not show up after being created

Author
13 Jul 2006 3:01 PM
Emily
Hi All,

I created the following user-defined function. It passed the syntax
check so I selected "OK". However, it was not added to the list under
"User Defined Functions". Anyone can tell me what is wrong with my UDF?
Thanks!

Create FUNCTION dbo.FnReportInstancesGet
        --@AfterTimestamp timestamp  = null output,
        (@AfterTimestamp timestamp  = null, --output,

        @MailingNameFilter DTTypeNameLong = '%',
        @ReportEntityFilter varchar(50) = '%',
        @AccountIDFilter int = null,
        @StatusMessageFilter varchar(255) = '%',
        @CreateSourceFilter varchar(50) = '%',
        @CreateDateBegin datetime = null,
        @CreateDateEnd datetime = null,
        @EffectiveDateBegin datetime = null,
        @EffectiveDateEnd datetime = null )


RETURNS TABLE
AS
RETURN
        (--SET NOCOUNT ON


        SELECT TOP 65536                        -- "65536" so we don't
accidentally overwhelm the UI (flex-grid specifically)


                ri.ReportInstanceName,                  -- "Account"
                ri.AccountID,
                ri.ReportEntity AccountName,            -- VI 7998
                ri.EffectiveDate,
                rt.PackageName,                                 --
"Report Package"
                ri.StatusMessage,
                ri.DueDate,
                ri.CreateDate,                                  --
"Create Date" in pace is preproc time
                ri.Priority,                                    --
"Critical Level"
                ri.TimestampValue,


                -- CORE-specific
                ri.ReportInstanceID,
                ri.Status,
                ri.CreateSource,
                ri.RetryDate,
                ri.RetriesLeft,
                ri.UpdateDate,
                ri.PivotalAccountMailingID,


                ri.CurrentAgentID,
                ri.CurrentStepInstanceID,
                ri.CurrentStepTypeID,
                ri.ReportTypeID,
                ri.OptionGroupID


        FROM
                ReportInstance ri


                inner join ReportType rt
                on rt.ReportTypeID = ri.ReportTypeID
        WHERE


                -- timestamp filtering


                ri.TimestampValue >
isnull(@AfterTimestamp,0x0000000000000000)


                -- other filtering
                and isnull(rt.PackageName,'') like @MailingNameFilter
                and isnull(ri.ReportEntity,'') like @ReportEntityFilter

                and (@AccountIDFilter is null or (ri.AccountID =
@AccountIDFilter))
                and isnull(ri.StatusMessage,'') like
@StatusMessageFilter
                and isnull(ri.CreateSource,'') like @CreateSourceFilter

                and ri.CreateDate between
isnull(@CreateDateBegin,'1900-01-01') and
isnull(@CreateDateEnd,'2100-01-01')
                and ri.EffectiveDate between
isnull(@EffectiveDateBegin,'1900-01-01')
and isnull(@EffectiveDateEnd,'2100-01-01')


        ORDER BY
                ri.TimestampValue DESC


        --SET @AfterTimestamp = @@dbts


        --SET NOCOUNT OFF
        --RETURN 0
        )

-Emily

Author
13 Jul 2006 3:28 PM
Arnie Rowland
Execute the code in Query Analyzer, and then in the object browser,
right-click on Functions and select Refresh.

--
Arnie Rowland*
"To be successful, your heart must accompany your knowledge."



Show quote
"Emily" <fir5tsi***@yahoo.com> wrote in message
news:1152802880.219430.63930@i42g2000cwa.googlegroups.com...
> Hi All,
>
> I created the following user-defined function. It passed the syntax
> check so I selected "OK". However, it was not added to the list under
> "User Defined Functions". Anyone can tell me what is wrong with my UDF?
> Thanks!
>
> Create FUNCTION dbo.FnReportInstancesGet
>        --@AfterTimestamp timestamp  = null output,
>        (@AfterTimestamp timestamp  = null, --output,
>
>        @MailingNameFilter DTTypeNameLong = '%',
>        @ReportEntityFilter varchar(50) = '%',
>        @AccountIDFilter int = null,
>        @StatusMessageFilter varchar(255) = '%',
>        @CreateSourceFilter varchar(50) = '%',
>        @CreateDateBegin datetime = null,
>        @CreateDateEnd datetime = null,
>        @EffectiveDateBegin datetime = null,
>        @EffectiveDateEnd datetime = null )
>
>
> RETURNS TABLE
> AS
> RETURN
>        (--SET NOCOUNT ON
>
>
>        SELECT TOP 65536                        -- "65536" so we don't
> accidentally overwhelm the UI (flex-grid specifically)
>
>
>                ri.ReportInstanceName,                  -- "Account"
>                ri.AccountID,
>                ri.ReportEntity AccountName,            -- VI 7998
>                ri.EffectiveDate,
>                rt.PackageName,                                 --
> "Report Package"
>                ri.StatusMessage,
>                ri.DueDate,
>                ri.CreateDate,                                  --
> "Create Date" in pace is preproc time
>                ri.Priority,                                    --
> "Critical Level"
>                ri.TimestampValue,
>
>
>                -- CORE-specific
>                ri.ReportInstanceID,
>                ri.Status,
>                ri.CreateSource,
>                ri.RetryDate,
>                ri.RetriesLeft,
>                ri.UpdateDate,
>                ri.PivotalAccountMailingID,
>
>
>                ri.CurrentAgentID,
>                ri.CurrentStepInstanceID,
>                ri.CurrentStepTypeID,
>                ri.ReportTypeID,
>                ri.OptionGroupID
>
>
>        FROM
>                ReportInstance ri
>
>
>                inner join ReportType rt
>                on rt.ReportTypeID = ri.ReportTypeID
>        WHERE
>
>
>                -- timestamp filtering
>
>
>                ri.TimestampValue >
> isnull(@AfterTimestamp,0x0000000000000000)
>
>
>                -- other filtering
>                and isnull(rt.PackageName,'') like @MailingNameFilter
>                and isnull(ri.ReportEntity,'') like @ReportEntityFilter
>
>                and (@AccountIDFilter is null or (ri.AccountID =
> @AccountIDFilter))
>                and isnull(ri.StatusMessage,'') like
> @StatusMessageFilter
>                and isnull(ri.CreateSource,'') like @CreateSourceFilter
>
>                and ri.CreateDate between
> isnull(@CreateDateBegin,'1900-01-01') and
> isnull(@CreateDateEnd,'2100-01-01')
>                and ri.EffectiveDate between
> isnull(@EffectiveDateBegin,'1900-01-01')
> and isnull(@EffectiveDateEnd,'2100-01-01')
>
>
>        ORDER BY
>                ri.TimestampValue DESC
>
>
>        --SET @AfterTimestamp = @@dbts
>
>
>        --SET NOCOUNT OFF
>        --RETURN 0
>        )
>
> -Emily
>
Author
13 Jul 2006 3:42 PM
Emily
Hi Arnie,

I ran the code in Query Analyzer. Then I got error "Parameter
'@AfterTimestamp' has an invalid data type."

FYI, I get the same error after I changed the data type to "binary" as
below:

@AfterTimestamp binary  = null,

Any advice on how to get rid of the error?

Thanks!
-Emily
Author
13 Jul 2006 4:01 PM
Arnie Rowland
My fault Emily,

I should have been more clear. You cannot use a timestamp datatype for the
INPUT parameter. Use a binary instead.

--
Arnie Rowland*
"To be successful, your heart must accompany your knowledge."



Show quote
"Emily" <fir5tsi***@yahoo.com> wrote in message
news:1152805373.067759.293230@i42g2000cwa.googlegroups.com...
> Hi Arnie,
>
> I ran the code in Query Analyzer. Then I got error "Parameter
> '@AfterTimestamp' has an invalid data type."
>
> FYI, I get the same error after I changed the data type to "binary" as
> below:
>
> @AfterTimestamp binary  = null,
>
> Any advice on how to get rid of the error?
>
> Thanks!
> -Emily
>
Author
13 Jul 2006 3:32 PM
Tracy McKibben
Emily wrote:
> Hi All,
>
> I created the following user-defined function. It passed the syntax
> check so I selected "OK". However, it was not added to the list under
> "User Defined Functions". Anyone can tell me what is wrong with my UDF?
> Thanks!
>
>

Did you Refresh the list in Enterprise Manager?  Are you sure you
created it in the right database?



--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Author
13 Jul 2006 3:44 PM
Emily
Hi Tracy,

I did Refresh the list in Enterprise Manager. I've been using the same
database.

Although it didn't give me any error, I got an error about data type of
"AfterTimestamp" when I ran the code in Query Analyzer as advised by
Arnie.

-Emily
Author
13 Jul 2006 4:02 PM
Tracy McKibben
Emily wrote:
> Hi Tracy,
>
> I did Refresh the list in Enterprise Manager. I've been using the same
> database.
>
> Although it didn't give me any error, I got an error about data type of
> "AfterTimestamp" when I ran the code in Query Analyzer as advised by
> Arnie.
>
> -Emily
>

Ok, so you hadn't actually created the function yet.  Loading the code
into QA doesn't do anything, you have to actually RUN the code...


--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Author
13 Jul 2006 7:35 PM
Emily
Hi Tracy,

You're right. That's what I have to do. Thanks!

-Emily

AddThis Social Bookmark Button