what is UDF in sql server 2005 and its uses

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivananda
    New Member
    • May 2013
    • 9

    what is UDF in sql server 2005 and its uses

    Hi, Every one
    hope every one doing well
    I am confused about UDF , how its work , what is the purpose of using the @ here ,

    here here is one code can u explain what it will going to do?

    if explained thank you ,
    Code:
    CREATE function [dbo].[UDF_Production_Report1_Working2]
    (
    	@TXTFromDate datetime,
    	@TXTToDate datetime,
    	@MFGPurpose varchar(10)
    )
    returns table
    as
    return
    (
    	SELECT a.ref_date,convert(integer,(sum(datediff(MI,b.start_time,b.end_time)) / 60)) + (convert(numeric(9,2),convert(numeric(9,2),(sum(datediff(MI,b.start_time,b.end_time)) - (convert(integer,sum(datediff(MI,b.start_time,b.end_time))/60) * 60))) / 100)) as hours FROM dps_mast a inner join dps_chld1 b on a.ref_no = b.ref_no and a.ref_date = b.ref_date inner join pls_mast c on a.pls_no = c.ref_no and a.pls_date = c.ref_date inner join prd_mast d on c.wo_no = d.no and c.wo_date = d.date where d.production_type = @mfgpurpose and a.ref_date between @TXTFromDate and @TXTToDate group by a.ref_date
    )
    go
    Last edited by Rabbit; Jun 11 '13, 03:13 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    The @ symbol designates what follows it as a variable. @x is a variable whereas just x is a field name or table name or some other existing object.

    Basically that code uses the two variables to filter the records using the two values that are passed into the function.

    Comment

    • nbiswas
      New Member
      • May 2009
      • 149

      #3
      This is table valued function that will return a table.
      '@' symbol indicates that whatever follows it is a variable.
      The function accepts 3 variables viz @TXTFromDate which is a datetime datatype, @TXTToDate also a datetime datatype and @MFGPurpose a varchar type.
      The query is performing a join on three tables viz. dps_chld1,pls_m ast,prd_mast and then the filtering clause is applied based on the function parameters and the result is projected.

      Hope this helps.

      Comment

      • shivananda
        New Member
        • May 2013
        • 9

        #4
        Thank you Biswas
        i got it its made my work simpler thanks a lot

        Comment

        Working...