I would offer the following only as a comment, but I think it's important enough to stand on its own.
A lot of the previous answers mentioned that one needs to beware of trailing spaces; and for sure that is true. However I've found that sometimes trailing spaces just want to get in there no matter what - particularly if you are doing a command line one-liner and need the space as a command separator.
This is the solution to that problem:
SET FOO=Bar
echo %FOO%
:: outputs Bar
SET "FOO="
echo %FOO%
:: outputs %FOO%
By wrapping the declaration in double quotes that way, the spacing issue can be avoided entirely. This can also really useful when variables are created by concatenating to eliminate spaces in between - for example - paths, e.g:
SET A=c:\users\ && SET D=Daniel
SET P="%a%%d%"
ECHO %P%
:: outputs "C:\Users\ Daniel"
:: Notice the undesirable space there