title: How do i use rowcount in Function in sqlserver?
body: <p>I have faced a problem using rowcount in function in sql server 2000.
  It shows an error like <code>Invalid use of 'UNKNOWN TOKEN' within a function.</code></p>
  
  <p>MY function is like this.</p>
  
  <pre><code>ALTER Function fnc_GetOpenShiftWorkID (@EMP_ID int,@Counter int,@date Datetime) returns int as
  BEGIN
  
    SET ROWCOUNT @Counter
    declare @result int
  
    if exists(select * from tbl_org_workinghrs WHERE EMP_ID=@EMP_ID and SDATE=@DATE)  
    BEGIN
  
      select  @result= WORK_ID 
      from    tbl_org_working_hrs work_hrs
              inner join tbl_org_shift_group sgroup on sgroup.WH_ID=work_hrs.WORK_ID
              inner join tbl_org_workinghrs workhrs on workhrs.GROUP_ID=sgroup.GROUP_ID
      WHERE   EMP_ID=@EMP_ID 
              and SDATE=@DATE 
      order by 
              IN_START
    END
    ELSE
    BEGIN
      if exists(select * from tbl_org_workinghrs where EMP_ID=0)
      BEGIN
        select  @result=WORK_ID 
        from    tbl_org_working_hrs 
        WHERE   IS_DEFAULTSHIFT=1
      END
    END
  
    return @result
  END
  </code></pre>