#Mathematica, 349 346 341 chars
h = If[StringMatchQ[#, ("H" | "Q" | "9" | "+") ...],
b = If[# > 0, ToString@#, "No"] <> " bottle" <>
If[# == 1, "", "s"] <> " of beer" &;
w = b@# <> " on the wall" &;
Print /@
StringCases[#, {"H" -> "Hello, world!", "Q" -> #,
"9" -> "" <>
Table[w@n <> ",\n" <> b@n <>
".\ntake one down, pass it around,\n" <> w[n - 1] <>
If[n == 1, ".", ".\n\n"], {n, 99, 1, -1}]}];,
"Source code contains invalid characters"] &
Mathematica, 349 346 341 chars
h = If[StringMatchQ[#, ("H" | "Q" | "9" | "+") ...],
b = If[# > 0, ToString@#, "No"] <> " bottle" <>
If[# == 1, "", "s"] <> " of beer" &;
w = b@# <> " on the wall" &;
Print /@
StringCases[#, {"H" -> "Hello, world!", "Q" -> #,
"9" -> "" <>
Table[w@n <> ",\n" <> b@n <>
".\ntake one down, pass it around,\n" <> w[n - 1] <>
If[n == 1, ".", ".\n\n"], {n, 99, 1, -1}]}];,
"Source code contains invalid characters"] &