July 23, 2009 at 7:49 am
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.
July 23, 2009 at 7:53 am
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
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply