Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:49:46+00:00 2026-06-16T17:49:46+00:00

I have a table valued function called split in my database and I want

  • 0

I have a table valued function called split in my database and I want to use it in a stored procedure.

When I say entity I mean department in company, as you know companies has department, section and other divisions under each other. When user creates entity it should have parent which is the company or another entity and maybe have a child which is another entity e.g IT>Development>software… etc.

Each one has id. I am storing these ids in one column like this 1,2,1. I need to split them when am showing to users.

Here is my function:

 ALTER FUNCTION [dbo].[Split](@String varchar(50), @Delimiter char(1))       
 returns @temptable TABLE (items varchar(50))       
 as       
 begin       
  declare @idx int       
  declare @slice varchar(50)       

 select @idx = 1       
    if len(@String)<1 or @String is null  return       

 while @idx!= 0       
 begin       
    set @idx = charindex(@Delimiter,@String)       
    if @idx!=0       
        set @slice = left(@String,@idx - 1)       
    else       
        set @slice = @String       

  if(len(@slice)>0)  
        insert into @temptable(Items) values(@slice)       

   set @String = right(@String,len(@String) - @idx)       
    if len(@String) = 0 break       
   end   
  return       
 end

Here is my stored procedure:

alter   procedure [dbo].[Emp_CompanyHirarchy]
@FK_CompanyId varchar(50),
@FK_EntityId varchar(50)
AS
  SELECT     
     Employee.EmployeeId, Employee.EmployeeNo,   
     Employee.EmployeeName, Employee.EmployeeArabicName, 
     OrgEntity.EntityName, OrgCompany.CompanyName, 
     Employee.DOB, Employee.Email
  FROM         
     Employee 
  INNER JOIN
     OrgEntity ON Employee.FK_EntityId = OrgEntity.EntityId 
  INNER JOIN
     OrgCompany ON OrgEntity.FK_CompanyId = OrgCompany.CompanyId
  WHERE     
     (Employee.FK_EntityId IN (dbo.Split(EntityHierarchy)))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:49:47+00:00Added an answer on June 16, 2026 at 5:49 pm

    In General;

    Select items From dbo.Split(YourColumnOrVariable,',')
    

    In your case, (since you are using IN) WHERE clause should be as;

    WHERE (Employee.FK_EntityId IN (Select Items FROM dbo.Split(EntityHierarchy)))
    --Items is the column name of the returning table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have this repeater which makes use of a public function called Test
I have a view (actually, it's a table valued function, but the observed behavior
I have table which contains double values stored in mysql database ...I need to
In SQL Server, I have a CLR integration based table valued function, GetArchiveImages. I
I have a scalar-valued function called DATEONLY that returns DATEADD(DD,0, DATEDIFF(DD,0, @DATETIME)), just like
Given: Oracle 10.2g is the database I have a table called emp. emp has
In a function called outputProducts I have added a submit button to my table:
We have a table value function that returns a list of people you may
Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
Let's say I have the following table: Value Time 0 15/06/2012 8:03:43 PM 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.