I\'m still learning my ropes with SQL Server and maybe this question sounds very naive/ridiculous. Please bear with me on this. :)
I saw a function in SQL Server defined
In general, yes you can use the value from a column for any place in SQL Server's syntax where a value is expected (as opposed to where a name is expected, such as the first argument to DATEPART
).
However, this is broken code - it appears to assume that each row will be evaluated in sequence and each row will be evaluated using values produced from previous rows. However, SQL Server only guarantees to perform one assignment (for the "last" row - however, with no ORDER BY
clause, "last" is ill-defined):
If the SELECT statement returns more than one value, the variable is assigned the last value that is returned.
Whether it may appear to work is no guarantee that more than a single assignment will actually take place.