commands like /execute if entity @p[nbt={Inventory:[{id:"minecraft:diamond"}]}] cannot be put in
/setblock <x> <y> <z> command_block 0 replace {Command:"execute if entity @p[nbt={Inventory:[{id:"minecraft:diamond"}]}]"
}
{{}}
because the quotation marks interfear
Invalid, you're trying to put a string in a string, without escaping quotation marks. You either need to use " for one string and ' for the other, or escape the inner string with backslashes.