Occasionally in DF, you'll run into foes that are completely insubstantial, and which cannot be affected by normal weaponry.
Here are some ways to attempt to deal with them.
Make weapons affect it
This is the adventurer standby in my games. My players are so enamored of Affect Spirits that they'll use it on weapons against anything that they either fail to hit or fail to hurt with magical weapons. It's a cheap and easy spell once you have it.
The Ghost Weapon enchantment will allow for a permanent way to carry this on a given weapon.
This has few downsides. The ones that PCs encounter most often are creatures that are unaffected by weapons over and above their Insubstantial advantage, and ones that cannot be killed in a normal sense. For those, even Affect Spirits isn't going to do the job. Some ghost types may be temporarily banished or dispersed by appropriate weapons but may not
Foes that are both Insubstantial and Diffuse will be affected by this spell but even so, it just will take longer.
Make it tangible.
A much less used option is a spell like Materialize. It's slow and expensive. 1 minute isn't terrible, but 50/10 cost is.
Attack it immaterially
Not all undead are immune to Mind Control spells or Communication and Empathy spells. Directly affecting it with spells which do not require a physical form can work. Will-resisted spells aren't a good bet against willful spirits, however, and some ghosts are of slain wizard-types and retain a lot of IQ. But it might be your best way to approach the problem offensively.
Actually deal with them
As in, a deal deal. Find out what's causing the spirit to do its haunting best, and appease its anger by solving the problem. Stop robbing the tomb, put back the things you stole, bury the bones in holy ground, lay it to rest, kill the murderer who killed the victim, etc. This can get awkward - what if the ghost's murderer is dead and the ghost wants the murderer's kid killed? Probably not high up on the list of ways to stay on the side of good. But it's worth attempting this where you think it's possible. Psychology (Undead) is useful here. Hidden Lore (Undead), not as much - it might tell you this type of undead is one you can negotiate with, but not how to go about doing it in a practical way.
This takes a solid amount of roleplaying and clue-assembling in many cases, but also might need appropriate social skills. This isn't the time for your half-orc barbarian with Callous to talk to the ghost, it's probably time for your bard or whatever you have that's close to one.
Some methods flat-out don't work.
Pray for Criticals
The old swing-until-I-get-a-3. That just won't work if your weapons won't affect it. I've seen this done.
Explosive Spells and Air Spells
Players sometimes mistake Insubstantial for "easily dispersed by wind." Not even all smoke-like monsters with Diffuse take extra damage from air currents, so Shape Air isn't an effective way to deal with them. Ghost-types are that plus generally won't be harmed by physical spells anyway. Same goes for holy water - unless it's affected specifically by it, it's unlikely to do much more than pass through the space the ghost is transiting through.
The Banish spell may work if it's a summoned spirit from another realm. If it's a native haunt of a slain but vengeful person . . . this spell is literally useless to affect it.
Similarly, other spells which affect other things - Turn Zombie, say - are not automatically able to affect ghosts.