Can a pinched nerve in the neck or back give sharp pains in the knees and legs?

Yes. The nerves connect the brain to the arms and the legs. Any interruption 'upstream' ie in the neck or back can affect things 'downstream' ie in the arms or legs.