DECLARE @BusinessId INT = 1

DECLARE @Days INT = 10
DECLARE @I INT = 1

DECLARE @DaysTable TABLE
(
	[DayNumber] INT
)
WHILE @I <= @Days BEGIN
	INSERT INTO @DaysTable
			([DayNumber])
	VALUES
			(@I)

	SET @I = @I + 1
END

DECLARE @MaxBrand INT = (SELECT COUNT(*) FROM [dbo].[Brand])
DECLARE @MaxCategory INT = (SELECT COUNT(*) FROM [dbo].[Category])
DECLARE @MaxGood INT = (SELECT COUNT(*) FROM [dbo].[Goods])

DECLARE @Cities TABLE
(
	[Name] VARCHAR(100)
)

INSERT INTO @Cities
        ( [Name] )
VALUES
	('Ìîñêâà'),
	('Ìàãàäàí'),
	('Óñòü ïèçäþéñê'),
	('Êàðàãàíäà')

DECLARE @Columns VARCHAR(MAX) = 
	(SELECT STUFF((
		SELECT ',' + '[' + [Name] + ']' 
		FROM @Cities FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, ''))

IF(OBJECT_ID('[tempdb]..[#Temp]') IS NOT NULL)
BEGIN
	DROP TABLE [#Temp]
END
	
CREATE TABLE [#Temp] 
(
	[Name] VARCHAR(100),
	[DayNumber] INT,
	[Flag] INT
)

INSERT INTO [#Temp]
        ( [Name], [DayNumber], [Flag] )

SELECT
	[c].[Name],
	[d].[DayNumber],
	1000000 * @BusinessId + (ABS(CHECKSUM(NEWID())) % @MaxBrand) * 10000 + (ABS(CHECKSUM(NEWID())) % @MaxCategory) * 100 + (ABS(CHECKSUM(NEWID())) % @MaxGood) AS [Flag]
FROM @Cities [c]
JOIN @DaysTable [d] ON 1 = 1

DECLARE @Query VARCHAR(MAX) = '
SELECT
	[DayNumber],' + @Columns + '
FROM [#Temp]
PIVOT
(
	MAX([Flag])
	FOR [Name] IN (' + @Columns + ')
) AS [x]'

EXEC(@Query)
