Wednesday 6 June 2012

SQL SERVER - APPLY


  1. An APPLY is used to join a table-valued-function with a table. APPLY are of two types: CROSS APPLY and OUTER APPLY
    A CROSS APPLY is used when you want to return only those records from your table where a value is returned by your table valued function.
    Whereas, an OUTER APPLY is used to return all records from your table regardless of the values returned by your table valued function.



    SELECT name.User_Id,name.UserName,name.Email,name.MobileNo,name.VisitedDate
    FROM allocate_site lead
    outer apply dbo.fn_get_latest_response_userwise(lead.User_ID) sales 
    cross apply dbo.fn_get_user_details(lead.User_ID) name
    inner join UserDetails users on users.ID = lead.User_ID
    WHERE lead.ProductId = name.ProductID 

No comments:

Post a Comment