How to make join Table with function cross apply to join by portionkey and portionNumber ?

ahmed salah 3,216 Reputation points
2020-11-25T20:54:45.087+00:00

I work on SQL server 2012 I face issue I can't join cross apply function with join table GlobalPartNumberPortions to

check portionkey and groupid exist on table GlobalPartNumberPortions

here is my statement

 update r set r.Status='Portion Exist Before'
 from #TempImporter r
cross apply
dbo.Split(r.GlobalPartNumber,'$') f where CAST (r.PortionNumber AS INT) = f.Id and r.PortionKey = f.Data

I need to add to statement above another check to portionkey and groupid on table GlobalPartNumberPortions

but I don't know how to join with function

by any way are this syntax below possible and correct or not

inner join  GlobalPartNumberPortions g on t.PortionNumber=g.GroupId  and t.PortionKey=G.PortionKey

join function with table full code as below correct or not

   update r set r.Status='Portion Exist Before'
     from #TempImporter r
    cross apply
    dbo.Split(r.GlobalPartNumber,'$') f where CAST (r.PortionNumber AS INT) = f.Id and r.PortionKey = f.Data
   inner join   GlobalPartNumberPortions g on t.PortionNumber=g.GroupId  and t.PortionKey=G.PortionKey
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,705 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K Reputation points
    2020-11-25T21:04:46.35+00:00

    Check and adjust this syntax:

    update r set r.Status='Portion Exist Before'
    from #TempImporter r
    cross apply dbo.Split(r.GlobalPartNumber,'$') f 
    inner join GlobalPartNumberPortions g on t.PortionNumber=g.GroupId  and t.PortionKey=G.PortionKey
    where CAST (r.PortionNumber AS INT) = f.Id and r.PortionKey = f.Data
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. EchoLiu-MSFT 14,571 Reputation points
    2020-11-26T02:58:56.393+00:00

    Hi @ahmed salah ,

    on t.PortionNumber=g.GroupId and t.PortionKey=g.PortionKey  
    

    whether t is incorrect, it should be r?

    I did a test and the following statement seems to work:

    update r set r.Status='Portion Exist Before'  
    from #TempImporter r  
    inner join GlobalPartNumberPortions g   
    on r.PortionNumber=g.GroupId and r.PortionKey=g.PortionKey  
    cross apply  
    dbo.Split(r.GlobalPartNumber,'$') f   
    where CAST (r.PortionNumber AS INT) = f.Id and r.PortionKey = f.Data  
    

    If you have any question, please feel free to let me know.
    If the response is helpful, please click "Accept Answer" and upvote it.

    Regards
    Echo


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues November--What can I do if my transaction log is full?
    Hot issues November--How to convert Profiler trace into a SQL Server table

    0 comments No comments