问题
I am using SQL Server 2012, i have a script by which i am inserting values to a table, in that script i have to convert the format of some DateTime variables on the basis of two parameters.
I can do it using CASE or if condition in sql. I am not allowed to make any Function or procedure in the database to which i can refer.
Is there any other way like creating a temporary function or temporary procedure within the script to apply condition alter the format for Datetime values?
回答1:
Yes you can:
CREATE PROCEDURE #usp_TempOne
@Input INT,
@Output INT OUTPUT
as
SET @Output = @Input * 2
RETURN
GO
DECLARE @i INT = 10, @o INT;
EXEC #usp_TempOne @i, @o OUTPUT
SELECT @o
来源:https://stackoverflow.com/questions/38768932/use-of-temporary-functions-or-procedure-within-a-script