Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe that the issue is a result of you passing a column <code>EmpDetails.EmpCode</code> name to the table-valued function, instead of a single value. You could try this instead:</p> <pre><code>DECLARE @EmpCode nvarchar(100); SELECT TOP 1 @EmpCode = EmpCode FROM Employee.tblEmp_Demographics WHERE RecordStatus='present'; select *,ROW_NUMBER() OVER (PARTITION BY EmpCode ORDER BY DateTaken DESC) AS RowNum, (select GradeName From Master.GradeMaster where GradeCode=Grade And Deleted=0) As Grade, SUM(Amount) OVER(PARTITION BY Grade) AS EmpAmount, SUM(DependentAmount) OVER(PARTITION BY Grade) As DepAmount, 0 As CheckNo from [dbo].[SELECT_AIRTICKET_DETAILS_BY_DATE](@EmpCode,getdate(),1) WHERE YEAR(DateTaken)=year(getdate()); </code></pre> <p>If you want results for multiple values from the <code>Employee.tblEmp_Demographics</code> table, you could iterate through each value (probably not best), or modify your table-valued function to return a result set with all EmpCode values, and then add a <code>WHERE</code> clause to filter the data as needed.</p> <hr> <p><em><strong>Edit</em></strong></p> <p>Something like this perhaps - note the modified function that returns all EmpCodes &amp; has one less parameter:</p> <pre><code>select *,ROW_NUMBER() OVER (PARTITION BY EmpCode ORDER BY DateTaken DESC) AS RowNum, (select GradeName From Master.GradeMaster where GradeCode=Grade And Deleted=0) As Grade, SUM(Amount) OVER(PARTITION BY Grade) AS EmpAmount, SUM(DependentAmount) OVER(PARTITION BY Grade) As DepAmount, 0 As CheckNo FROM [dbo].[SELECT_AIRTICKET_DETAILS_BY_DATE](getdate(),1) AS [Tickets] INNER JOIN Employee.tblEmp_Demographics ON tblEmp_Demographics.EmpCode = [Tickets].EmpCode AND tblEmp_Demographics.RecordStatus = 'present' WHERE YEAR(DateTaken) = year(getdate()); </code></pre> <p>With this solution, the function returns all EmpCodes, but we filter out the unnecessary ones by performing an <code>INNER JOIN</code> on the <code>Employee.tblEmp_Demographics</code> table.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload