SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert value only if other value exists
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nikl
Starting Member

Germany
7 Posts

Posted - 05/10/2013 :  06:59:03  Show Profile  Reply with Quote
I am trying to add a value to all entries that already own another value.
I was hoping this code woudl do the trick:

SELECT value FROM catalog_product_entity_varchar
WHERE attribute_id=608 and value="XYZ"
UPDATE catalog_product_entity_varchar SET value = "XYZ_2"
WHERE attribute_id=668;

But instead of being only applied to the entries found via SELECT value FROM catalog_product_entity_varchar
WHERE attribute_id=608 and value="XYZ" it is applied to all entries. How can I make sure value XYZ_2 is only added to the entries that already include value XYZ?
Thank you!

ahmeds08
Aged Yak Warrior

India
693 Posts

Posted - 05/10/2013 :  07:07:54  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
UPDATE catalog_product_entity_varchar SET value = "XYZ_2"
WHERE attribute_id=668 and value='XYZ';

mohammad.javeed.ahmed@gmail.com
Go to Top of Page

nikl
Starting Member

Germany
7 Posts

Posted - 05/10/2013 :  07:31:46  Show Profile  Reply with Quote
This will replace XYZ with XYZ_2 in attribute668. However I need to add XYZ_2 to attribute668 if attribute608 has XYZ as value.

Isn't this possible or does my explanation make no sense?

Edited by - nikl on 05/10/2013 08:57:17
Go to Top of Page

Mark W
Starting Member

2 Posts

Posted - 05/10/2013 :  10:27:32  Show Profile  Reply with Quote
quote:
Originally posted by nikl

This will replace XYZ with XYZ_2 in attribute668. However I need to add XYZ_2 to attribute668 if attribute608 has XYZ as value.

Isn't this possible or does my explanation make no sense?



If you trying to concatenate the two values, try this

UPDATE catalog_product_entity_varchar SET value = value + 'XYZ_2'
WHERE attribute_id=668 and value='XYZ';
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 05/10/2013 :  10:51:38  Show Profile  Reply with Quote
It's much more helpfull to explain what you want to do in words. Then followup by showing sample data and expected output. Providing a query that doesn't work, doesn't realy help. That being said, here ar some links that can help you perpare your sample data in a consumable format. That will help describe teh problem and it gives us code we can run. In return you get a working solution.

http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

nikl
Starting Member

Germany
7 Posts

Posted - 05/13/2013 :  05:36:37  Show Profile  Reply with Quote
Ok I took a closer look at this and this is as good as I will be able to explain this with my limited to non-existent knowledge.
To prevent me from mixing up real db notations with shortened xyz-like ones, I will use my actual table notations.

I have a table 'catalog_product_entity_varchar' which includes these columns:
value_id, entity_type_id, attribute_id, store_id, entity_id, value
Entries in this table with 'attribute_id' = 608 can include the value "versandfrei_info" - but not necessarily.
I now need to find all entries with attribute_id = 608 and value = "versandfrei_info", take their entity_id and add to each entry in this 'catalog_product_entity_varchar' with matched entry_id and attribute_id = 668 the new value "versandfrei_info2".

Maybe this image will help to understand what I am trying to do:

As you can see there are two entries with matching entity_id, one with attribute_id 608, the other with 668. Now I need to check if attribute_id equals 608 and value equals "versandfrei_info" and then add "versandfrei_info2" for the entry that has the matching entity_id and whose attribute_id is 668.

Edited by - nikl on 05/13/2013 11:29:05
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000