Click here to Skip to main content
15,887,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have some data with given below

Product table

ProductID	ProductName	             SupplierID
1	           Chai    	                1
2	           Chang	                1
3	           Aniseed Syrup	        1
9	           Mishi Kobe Niku  	        4
10	           Ikura	                4
11	           Queso Cabrales	        5
12	           Queso Manchego La Pastora	5
74	           Longlife Tofu	        4




I want to update the table on a criteria and append a suffix to the column values on the given 'Where' condition
as shown below
I want to update those record who have 1 and 4 as supplier id by appending v.1 string to the column value
ProductID	ProductName	       SupplierID
1	           Chai .v1    	          1
2	           Chang.v1	          1
3	           Aniseed Syrup.v1	  1
9	           Mishi Kobe Niku.v1  	  4
10	           Ikurav.14	          4


SQL
Declare
@Suffix varchar(10)='v.1'
Update Product
set ProductName=(select ProductName from Product where SupplierID in (1,4)+@Suffix)
where
where SupplierID in (1,4)

But it wont work . Please help
Posted
Updated 29-May-14 22:28pm
v2

1 solution

SQL
update product set productname = productname + '.v1'
where supplierid in (1, 4);
select * from product
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 30-May-14 4:57am    
5
Peter Leow 30-May-14 6:32am    
Thanks Karthik, haven't "seen" you for a while, what a surprise!
Karthik_Mahalingam 30-May-14 7:39am    
HI peter,
i was into an hectic project for past couple of months, no time to take part in CP , so getting free nowadays..
hope i will be active in CP hereafter :)
Kunal Ved 30-May-14 8:10am    
I feel fortunate, 2 techies corresponding via my question ,
I got my solution anyways ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900