I’d make this a scalar UDF as it is easier to consume the output.
CREATE FUNCTION dbo.GetNextFriday(
@D DATETIME
)
RETURNS DATETIME
WITH SCHEMABINDING, RETURNS NULL ON NULL INPUT
AS
BEGIN
RETURN DATEADD(DAY,(13 - (@@DATEFIRST + DATEPART(WEEKDAY,@D)))%7,@D)
END
More Related Contents:
- Is it possible to write single query on two table which are not connected to each other?
- Insert an image in a column of a table that already has 5 columns
- How to avoid the “divide by zero” error in SQL?
- SET versus SELECT when assigning variables?
- Querying data by joining two tables in two database on different servers
- sql query to return differences between two tables
- Real life example, when to use OUTER / CROSS APPLY in SQL
- How to print VARCHAR(MAX) using Print Statement?
- Convert Xml to Table SQL Server
- Concatenate values based on ID
- Splitting delimited values in a SQL column into multiple rows
- How to find current transaction level?
- How to connect to SQL Server from another computer?
- EXISTS vs JOIN and use of EXISTS clause
- Restrict an SQL Server connection to a specific IP address
- Custom aggregate function (concat) in SQL Server
- Average of multiple columns
- Cumulative Total in MS Sql server [duplicate]
- How do I find the data directory for a SQL Server instance?
- How can I delete using INNER JOIN with SQL Server?
- Convert varchar into datetime in SQL Server
- How to do pagination in SQL Server 2008
- Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one sql statement
- Execute Stored Procedure from a Function
- How to write UPDATE SQL with Table alias in SQL Server 2008?
- SQL Server 2008- Get table constraints
- Why are logical reads for windowed aggregate functions so high?
- Add a row number to result set of a SQL query
- Connect different Windows User in SQL Server Management Studio (2005 or later)
- How to Select Every Row Where Column Value is NOT Distinct