update table with split function

  • hi Friends i have a problem

    i have a two tables

    1.Customer

    2,Purchases

    customer table has [ Customer_id(int),name(varchar)]

    purchases table has [ purchase_no(int)(identity),Customer_id(int),Delivered(bool)]

    i will all the custmer_id's in string format

    and i want to update the delivered field in the purchases table with bool =1 and

    customer_id with split function

    i am using this query - where fnSlplit is spliting the customer_id

    into table format but not updating the purchases table

    UPDATE purchases SET Delivered= 1

    INNER JOIN dbo.fnSplit(@CustomerList,',') AS S

    ON

    REDEMPTION_CODE = S.ID

    WHERE REDEMPTION_CODE = S.ID

    please help to solve this problem.

  • it's just syntax; when you need to update and join on a table, you need an alias and an xplicit FROM:

    declare @CustomerList varchar(max)

    Set @CustomerList='IBM,Dell,Google'

    UPDATE MyAlias

    SET Delivered= 1

    From purchases MyAlias

    INNER JOIN dbo.fnSplit(@CustomerList,',') AS S

    ON

    MyAlias.REDEMPTION_CODE = S.ID

    WHERE MyAlias.REDEMPTION_CODE = S.ID --duplicates the join condition...not needed

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply