Know the Difference
Recognize that the techniques you use in a greenside bunker are totally different than those you use if you find your ball in sand on the fairway. Rule no. 1 for both shots, however, is to get out of the sand.
Make these adjustments to your normal swing when you are in the sand in a greenside bunker. First, open the face of your club and address the ball with an open stance with the clubface pointing at the hole. Grip your sand wedge further down the shaft, and hold your club more loosely than you normally would. Stand a little further away from the ball and "wiggle" your feet into the sand both to ascertain the conditions of the sand and to lower the arc of your swing. Place the majority of your weight on the leg closer to the flag. Finally, on your backswing, break your wrists immediately to create a steeper swing and hit the sand about 2 inches behind the golf ball.
A Fairway Bunker
Gain confidence when you find your golf ball in a fairway sand trap and you are 150 yards or more from the green. Address the ball as you normally would in the fairway with your ball centered or a little forward in your stance. If you are not worried about getting the ball out of the sand, take a little more club than you would for a normal shot. For example, if you would hit a 6-iron on the fairway, use a 5-iron in the trap. Swing the club as you normally would, accelerate it through the shot and take as little sand as possible. Finally, don't try to help the ball out of the sand trap because, if you have chosen the right club, its face will do that for you.
Practice Makes Perfect
Practice both shots to learn how to control them and to gain confidence in your technique. If your golf club or practice range does not have sand bunkers for practicing long shots, hit balls off bare dirt and try to take as little of it as you can while hitting the ball solidly.