Getting the number of cores

In order to set parameters by script during an installation, you may need to get the number of cores affected to an instance.
Here is the script

ALTER DATABASE DataBaseName 
DECLARE @NumberOfCores INTEGER
SELECT @NumberOfCores = COUNT(cpu_id) FROM sys.dm_os_schedulers
WHERE status='VISIBLE ONLINE'
PRINT 'Number of cores: ' + CONVERT(VARCHAR,@NumberOfCores)