Forum Discussion

TheYellow's avatar
TheYellow
Copper Contributor
Feb 05, 2024

How can I declare a variable and use it on the same select for the next column

How can I set the same values in column1 and column2. Thanks!

 

DECLARE @Value FLOAT 
SET @Value = 1000.0 + floor(10000 * RAND(convert(varbinary, newid())))
;WITH cte AS
(
  SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) - 1 AS [Incrementor]
  FROM   [master].[sys].[columns] sc1
  CROSS JOIN [master].[sys].[columns] sc2
)
 
SELECT
DATEADD(DAY, cte.[Incrementor], '2020-01-01') Date, 
1000.0 + floor(10000 * RAND(convert(varbinary, newid()))) Column1,
1000.0 + floor(10000 * RAND(convert(varbinary, newid()))) Column2
 
FROM   cte
WHERE  DATEADD(DAY, cte.[Incrementor], '2020-01-01') < GETDATE();
GO

 

Resources