Quantcast
Viewing all articles
Browse latest Browse all 3145

With Clause in SQL Server Function (UDF)

I am trying to Write a function the needs with clause with in the function soCreate FUNCTION Temp(@Begin_Date DATE, @END_Date DATE)RETURNS TABLEASRETURN(---Also I need to declare var1 and var2 that will read data from a table for parametersWITH Emp AS (Select * FROM emp where hireDate BETWEEN @Begin_Date AND @END_Date),dep AS(Select * from dept where deptStartDate BETWEEN @Begin_Date AND @END_Date)---Then I need to returnSelect * from dept, emp where emp.empno = dept.empno;)So below are the questions I am unclear about1. How to declare var1 and var2 that will read data from a table for parameters2. How return all resultset.The key is to be able to filter records before join.Can we do it just in a view......? Any help is appreciated

Viewing all articles
Browse latest Browse all 3145

Trending Articles