Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
tecknowledge1164
Starting Member
25 Posts |
Posted - 2010-02-05 : 12:22:11
|
| I have a bit of an unusual query that I need to figure out. I am converting some data that starts with looping through a data reader. I look up a templateID based on certain fields in the data reader. Once I find that I go to the Template table and find the row with that TemplateID and a Lot Number from the data reader. The trick is that the Lot Number can be in one of 32 fields in the Template Table. Once I identify which field it is in, I take that value to an array and match it up with a string value that I will use to update a row in another table. So this array looks like:Field 1, String 1Field 2, String 2...Field 32, String 32My question is, what is the best way to figure out which field contains the value I need? I'm thinking I may have to set up a For loop where I say "SELECT * FROM Templates WHERE Field 1 = LotNumber AND TemplateID = id. If that doesn't return a row I move on to Field 2 and so on. Once I find a match I could exit the loop and use that value to look up the string. So if Field 10 had the lot and templateID, I go to the array and match Field 10's string value and update the record. I would like to see if there is a more efficient or elegant way of doing this. It is like instead of looking for a needle in a haystack I need to first find the right haystack based on where the needle is!Any advice on this would be appreciated. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 12:31:24
|
| can you post some data from table and then explain. that should make your scenario clear. see below for how to posthttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
tecknowledge1164
Starting Member
25 Posts |
Posted - 2010-02-09 : 16:18:15
|
| Never mind, I figured it out. Thanks anyway. |
 |
|
|
|
|
|