SQL select statement help - Microsoft SQL Server 2005 - SQL Syntax
Posted on 2009-12-29
Table Name: index
doc_id index_id doc_field value person_nbr
58B57721 C192173B 8A2E7328 553 2D28D988
58B57721 46A5DB1E 96A237F3 1602 2D28D988
58B57721 CF4946CB DE2A292E 745 2D28D988
58B57721 446C6068 5AFC40D0 20090601 NULL
I would like to write a select statement on the above tables that will return the value column's record of 20090601 above from table index.
I also need the index.doc_field_id = '5AFC40D0', which I can hard-code, and I know the person_nbr going in, but it is not associated with that particular row (there is a NULL value). I do not know the doc_id going into the query. There are also many records in the table with multiple doc_id's and multiple person_nbr's = the above set is merely a sample.
I basically need to say something like "Where the doc_id's are the same, and the other 3 records have my person_nbr and this one doesnt, and the len(value) = 8, then return that value. The person_nbr not existing is killing me here. I need help writing the code, if possible, that will give me that value.