The way SQL queries work is that
you run the SQL, get the result object or nil.
Then you can get info from the object.
The object contains all the rows and columns from the SQL query.
local entry = 123123
local Q = WorldDBQuery("SELECT npcflag, name FROM creature_template WHERE entry = "..entry)
local npcflag = Q:GetUInt32(0)
local name = Q:GetString(1)
print("No rows found or there was some error")
The indexes start from 0, so GetUInt32(0) gets the NPCflag
You should usually always check if the result, Q in this case, is nil and handle that case or you may get nil errors that can cripple the script.
The error in your script is that you are using Q directly in the math.
This means that you are trying to for example do 100 + player, which doesnt work obviously as player is not a number.
So what you need to do is to get the value with a function from the query result and use that in the math.
See this for more: