标签:and esc center 简写 输出参数 insert lis context 入参
create procedure sp_name @[参数名] [类型],@[参数名] [类型] as begin ......... end 以上格式还可以简写成: create proc sp_name @[参数名] [类型],@[参数名] [类型] as begin ......... end /*注:“sp_name”为需要创建的存储过程的名字,该名字不可以以阿拉伯数字开头*/ 调用存储过程 存储过程可以在三种环境下被调用: command命令下,基本语法为:exec sp_name [参数名]; SQL环境下,基本语法为:call sp_name [参数名]; PL/SQL环境下,基本语法为:begin sp_name [参数名] end; 删除存储过程 1.基本语法: drop procedure sp_name
USE DataBase --数据库名 GO /****** Object: StoredProcedure [dbo].[dbSixMonthConversion] Script Date: 2019/8/30 14:47:10 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= ALTER PROCEDURE [dbo].[dbProcdureName] -- 存储过程名称 @currentDate DATETIME -- Add the parameters for the stored procedure here AS BEGIN CREATE TABLE #TempTable --创建临时表缓存数据 ( MonthCount INT , YearCount INT , AnyValue INT ); DECLARE @i INT; --循环插入数据 SET @i = 0; WHILE @i < 6 BEGIN DECLARE @date DATETIME = DATEADD(MONTH, -@i, @currentDate); INSERT INTO #TempTable ( MonthCount , YearCount , AnyValue ) VALUES ( YEAR(@date) , -- MonthCount - int MONTH(@date) , -- YearCount - int ( SELECT COUNT(1) FROM atjubodb.dbo._User WHERE ID NOT IN ( SELECT DISTINCT UserID FROM atjubodb.dbo._Order WHERE CreateTime IS NOT NULL AND State IS NOT NULL AND State > 0 AND CreateTime <= @date )--‘2019/8/1 0:00:00‘ AND ID IN ( SELECT DISTINCT UserID FROM atjubodb.dbo._Order WHERE CreateTime IS NOT NULL AND State IS NOT NULL AND State > 0 AND YEAR(CreateTime) = YEAR(@date) AND MONTH(CreateTime) = MONTH(@date) ) ) ); -- AnalyticalValue - int SET @i = @i + 1; END; SELECT * FROM #TempTable; DROP TABLE #TempTable; RETURN 1; -- Insert statements for procedure here END;
DateTime currentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); //输出参数 SqlParameter paramOut = new SqlParameter("return_value", 0); paramOut.Direction = ParameterDirection.Output; //输入参数 SqlParameter paramIn = new SqlParameter("currentDate", currentDate); var querys = dbContext.Database.SqlQuery<AppSixMonethStatisics>("EXEC [dbo].[dbProcdureName] @currentDate,@return_value output", new object[] { paramOut,paramIn }).ToList();
SET @i = 0; WHILE @i < 6 BEGIN END;
标签:and esc center 简写 输出参数 insert lis context 入参
原文地址:https://www.cnblogs.com/axqa/p/11436456.html