Updating information in a table

  • Hello,

    I have just jumped headfirst into the world of SQL this week, and am looking for some help updating information in one of my tables.

    We are running MS SQL 2000 with the iCode Everest business software, and the eCommerce addon. I currently have about 3000 part numbers where I need to attached images that will show on our website. The only way to do this through Everest is to open the item profile for each part number, and manually browse and select the image files for that item (4 different image files per item). As you can imagine this would take A LOT of time to complete, and we are under tight deadlines to get our site up and running.

    The only other option that occured to me was to create an Excel file with the item code , and the four image file fields, and then import them into the SQL table that this information is pulled from. Unfortunately when I attempt this, I receive an error stating (in lamens terms) that the item code is already listed in the table and duplicate entries cannot be added. What I need to do is just update each item code in the table to have the image file names listed under their respective headers, without overwriting any other information in the item code line.

    If anyone has any advice for me, or could point me in the right direction, it would be greatly appreciated.

    Thank you in advance.

  • I am sure there are several ways to do this. 

    How about create a new table with the excel file that you created, and then update the image filename columns by joining Item code line to this new table. 

    import data from excel file to the new table say "itemImageFileName"

    update itemCodeLine

    set imageFilename1 = B.imageFilename1 , imageFilename2 = B.imageFilename2,...

    from itemCodeLine A inner join itemImageFileName B

    where A.itemPartNumber = B.itemPartNumber

     

     

     

  • Hi,

    Generally if you have table type questions it is easier to get help if you give a little example of the table structure, it helps the geeks see what you need.  I am going to make a guess at what you are doing.

    First you said you were going to make an Excel spreadsheet of the Item and the imagedata.

    then you said it was crashing on the insert because of the duplicate record.

    I am guessing that this is your excel table

    Part IDImages
    1image Data1
    1image Data2
    2image Data 3
    2image Data 4

    The problem on your insert is that you are making a table just like this in SQL and the Part ID column cannot be the IDentity collumn because of the repeated ID numbers.

     

    You need to normalize your data to Either 2 or three tables Depending on if the images are on to many with the parts or if the images are Many to Many with the parts.

    If an Image Can only have One Part as its Parent, then The Image table can have a column for the part number in it. Like this:

    Part IDPart Information
    11/4 inch hex cap screw
    21/2 inch hex cap screw
    33/4 inch hex cap screw
    45/8 inch hex cap screw

    Then You Need the images table with a foreign key relating to the above table like this

    Image IDPart IDImage Data
    11Image Data 1
    21Image Data 2
    32Image Data 3
    42Image Data 4

    If However, You have one image that can be used for several parts, Then You have to have 3 Tables one for the Pictures, One for images, and one for the Join of the 2 tables. Like These:

    Part IDPart Information
    11/4 inch hex cap screw
    21/2 inch hex cap screw
    33/4 inch hex cap screw
    45/8 inch hex cap screw

    Image IDImage Data
    1Image Data 1
    2Image Data 2
    3Image Data 3
    4Image Data 4

    PartImageIDPart IDImage ID
    111
    212
    323
    424

    If I have guessed correctly then I would suggest that you actually export your data into different excell tables before the import. otherwise you will need to do the inserts seperately and do a select distimct for the part numbers.

     

    Sorry for the long winded answer but I think you will find this helps a bit.  Also I would Suggest "SQL for Smarties" by CELKO it has a lot of design ideas and he is very active in the google groups.

     

    Hope that helps

     

    Tal McMahon

     

     


    Kindest Regards,

    Tal Mcmahon

  • Sorry, I should have included an example of the table I am working with.

    ActiveItemnoDescriptimageactualimagethumbimageiconimagesmall
    TEXAMPLE1EXAMPLE SKU 1actual-example1.gif100-example1.gif50-example1.gif50-example1.gif
    TEXAMPLE2EXAMPLE SKU 2actual-example2.gif100-example2.gif50-example2.gif50-example2.gif
    TEXAMPLE3EXAMPLE SKU 3actual-example3.gif100-example3.gif50-example3.gif50-example3.gif
    TEXAMPLE4EXAMPLE SKU 4actual-example4.gif100-example4.gif50-example4.gif50-example4.gif
    TEXAMPLE5EXAMPLE SKU 5actual-example5.gif100-example5.gif50-example5.gif50-example5.gif

    This is an example of both the sql table and the excel file I created to import the data I need. I wanted the Excel file to match the table as close as possible. Of course the sql table does not have the actual image file names in it.. yet.

    What I was hoping would happen during the import was the "itemno" fields match up, and then sql would import the image filenames into their respective columns in the table. Basically the same as a VLOOKUP in MS Excel. The only information that needs to be imported into the table is the image filenames, unfortunately when I attempted the import I believe it was trying to import the itemno column as well.

    As you can see from the example table, there are three different image file sizes per itemno, and each itemno has it's own set of images, so I don't believe creating three seperate tables would help me out. Also the sql table in question has much more information in it than what is showing in my example, such as costs, stock information, sales history, etc... All this of course would have to remain untouched during any import I am able to do.

    I appreciate everyones help, and the longer winded the answers the better so no need to apologize!

  • Does anyone have any other ideas?

Viewing 5 posts - 1 through 4 (of 4 total)

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