The table contains unique records for a specific field (FILENAME). Although the entries are unique, they are actually just duplicates that contain only text. How can you return and group similar or similar records and update empty fields?
The table below is typical for entries. Each entry has a file name, but this is not a key field. There is one database entry with metadata that I would like to populate for document metadata that can only be identified by the first n characters.
A variable is the original file name that always changes the length of a character. The constant is that the prefix is ββalways the same.
FILENAME / DWGNO / PROJECT 52349 / 52349 / Ford 52349-1.dwg / / 52349-2.DWG / / 52349-3.dwg / / 52351 / 52351 / Toyota 52351_C01_REV- / / 52351_C01_REV2- / / 123 / 123 / Nissan 123_rev1 / / 123_rev2 / / 123_rev3 / /
The table should look like this.
FILENAME / DWGNO / PROJECT 52349 / 52349 / Ford 52349-1.dwg / 52349 / Ford 52349-2.DWG / 52349 / Ford 52349-3.dwg / 52349 / Ford 52351 / 52351 / Toyota 52351_C01_REV- / 52351 / Toyota 52351_C01_REV2-/ 52351 / Toyota 123 / 123 / Nissan 123_rev1 / 123 / Nissan 123_rev2 / 123 / Nissan 123_rev3 / 123 / Nissan
At first I tried to join the table and check the length, but "LEFT (FILENAME, 10)" does not return all the results.
USE MyDatabase SELECT x.DWGNO AS X_DWGNO, y.DWGNO AS Y_DWGNO, x.FILENAME AS X_FILENAME y.FILENAME AS Y_FILENAME x.DWGTITLE, x.REV, x.PROJECT FROM dbo.DocShare x
Also tried something different based on a similar post, but it doesn't work either.
USE MyDatabase SELECT X.E_DWGNO, y.DWGNO AS Y_DWGNO, x.FILENAME AS X_FILENAME y.FILENAME AS Y_FILENAME x.DWGTITLE, x.REV, x.PROJECT FROM dbo.DocShare x WHERE EXISTS(SELECT x.FILENAME FROM dbo.DocShare WHERE x.FILENAME = LEFT(y.FILENAME LEN(CHARINDEX('.', y.FILENAME, 0)))) ORDER BY y.FILENAME