Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tables one with images of equipment and another with description of the equipment (which includes Company, Branch, Equipment number, VIN). Each equipment record has a potential to have 6 photos. The photos are separate and I am trying to figure out how to relate them to the equipment table.
I was able to use (SELECT * FROM OPENROWSET(BULK N''' + @imgString + ''', SINGLE_BLOB) as tempImg))' With a SET WHILE statement to iterate through a list of images and the filename
This gives me a table with ImageID, ImageDescription(extracting the filename from the path), and the Image. On my Equipment table I have 6 fields with a potential to have 6 images and the names are the filename. I am wondering how to link the two. Not every equipment has an image.
Posted

1 solution

The way I would do it is to have an ID column on your equipment row, and link that to your images table with another row:
Equip Table:
id, name, part no, description

Images Table:
id, immageData, EquipId
You can then use the Equipment ID to return all the relevant images for a piece of equipment with a trivial query.
 
Share this answer
 
Comments
Shweta N Mishra 11-Nov-14 11:24am    
+5
adamolson 21-Nov-14 18:01pm    
Should I use an Identity Column for Equipment ID
OriginalGriff 22-Nov-14 4:28am    
Depends: personally I prefer GUID's, unless it's a log file where the ID is just there for ordering and to ensure uniqueness.

If I want to insert a new row to a table and I will need the ID to link to a different table, I generally use GUID rather than identity, so I can assign the value in my code rather than having to retrieve it's new value from SQL after the insert.

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