SPACE is a scalar string function that generates a varchar string consisting only of space (ASCII 32) characters. It is commonly used to pad text, build fixed-width files, or concatenate readable output inside queries and stored procedures. The function takes a single numeric argument that indicates how many spaces to return. If the argument is zero, an empty string is returned; if it is NULL, the result is NULL. Most engines cap the maximum length at the platform’s varchar limit (for example 8,000 or 65,535 characters). Passing a negative number raises an error in some dialects and is silently converted to zero in others.
REPLICATE, REPEAT, CHAR, LPAD, RPAD, CONCAT, TRIM
SQL Server 7.0 and MySQL 3.23
It returns a string containing exactly n blank space characters (ASCII 32). If n is 0, an empty string is returned.
Yes. Combine SPACE with string concatenation or with RIGHT/LEFT to pad values where lpad/rpad are unavailable.
In SQL Server, SPACE returns varchar. Explicitly CAST to NVARCHAR if you need Unicode.
Use REPEAT(' ', n) which produces the same string of spaces and is ANSI-compliant.