Use of temporary functions or procedure within a script

橙三吉。 提交于 2019-12-22 15:24:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!