John, It all depends on the agency. It takes awhile to go from a patrol officer and make their way up through the ranks. In my agency, most detectives have several years on...typically 5+ before moved over to detective. The larger the agency (such as NYPD) offers many more opportunities so it is possible for somebody to become a detective in a shorter time.
Often times, larger agencies will have various parts of the agency with their own detectives. For example, many agencies will have a Burglary Unit, Auto Theft Unit, Robbery Unit...and each of these may have their own detectives. So, an officer could do a couple of years on the street and end up as a burglary detective. After some time working burglaries, they may make their way up to violent crimes and then eventually homicides. Each agency is different.
Detective should not be confused with rank...For example, one could be a Sgt in Patrol or be a Sgt as a detective. Or, an officer could be on the street in patrol or working as a detective. Many of our narcotics detectives still hold the rank of officer. Becoming a LT would be the next step after Sgt. Andy could have been a Sgt as a detective and moved up one rank to Lt in just a few years. There are a lot of variables on getting promoted when it comes to rank.
As for realism, NYPD Blue is not realistic at all....When it first came out in 1993, it was probably the most realistic show on TV because it shows investigations and interpersonal relationships. Over the years, many more shows came along but NYPD Blue remains one of my favorites (the older episodes anyway).
IMO, the most realistic show that is a drama style would be The Wire. Although not real, it shows a lot of what happens on the streets of Baltimore. Again, most is fake but when it comes to TV Drama, it would be the most realistic. If you want REAL investigations for homicides, check out The First 48. Those are real detectives working real cases.