SQLTeam.com | Weblogs | Forums

How to execute function for every row?


#1
select getdate() from sys.all_columns

How to execute getdate() more than once?


#2

One way would be to create a UDF

CREATE function dbo.mygetdate() RETURNS datetime AS
BEGIN 
 RETURN GETDATE();
END 
GO

SELECT dbo.mygetdate() FROM sys.all_columns

#3

What is it that you're actually trying to do in the big picture? Are you trying to generate random dates or trying to show the exact update time for each row to do something like temporally measure performance or ???

If the latter, then the function that @JamesK posted will absolutely do the trick.


#4
select rand()
from sys.all_columns()

#5
 SELECT TOP 1000000
        RAND(CHECKSUM(NEWID()))
   FROM      sys.all_columns ac1
  CROSS JOIN sys.all_columns ac2
;