sqlserver 临时表操作
来源:互联网 发布:淘宝美国代购推荐 编辑:程序博客网 时间:2024/05/19 00:12
--按状态查询if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[StatusType]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[StatusType] GO CREATE PROCEDURE [dbo].[StatusType](@statustype nvarchar(50),@startdate nvarchar(200),@enddate nvarchar(200)) AS declare @pronum int CREATE TABLE #t(Status nvarchar(50),ProNum nvarchar(50)) set @pronum = (select count(*) from employee where Status='在职' and factorytime >= @startdate and factorytime<= isnull(@enddate,getdate())) INSERT INTO #t VALUES ('在职',@pronum) set @pronum = (select count(*) from employee where Status='离职' and factorytime >= @startdate and factorytime<= isnull(@enddate,getdate())) INSERT INTO #t VALUES ('离职',@pronum) set @pronum = (select count(*) from employee where Status='辞退' and factorytime >= @startdate and factorytime<= isnull(@enddate,getdate())) INSERT INTO #t VALUES ('辞退',@pronum) IF (@statustype ='') select * from #t where 1=1 ELSE select * from #t where Status =@statustype GO--按厂区查询if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PlantType]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[PlantType] GO CREATE PROCEDURE [dbo].[PlantType](@planttype nvarchar(50),@startdate nvarchar(200),@enddate nvarchar(200)) AS declare @pronum int select Id as PlantId,Name,(select count(*) from employee where PlantId = Plant.Id) as ProNum into #t from Plant IF (@planttype ='') select * from #t where 1=1 ELSE select * from #t where PlantId =@planttype GOexec [dbo].[PlantType] '','1990-01-01','2080-08-08'
//数据库连接字符窜 SqlConnection conn = new SqlConnection(DBHelper.strCon); string proc_name = "PlantType"; SqlCommand cmd = new SqlCommand(proc_name, conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter sp = cmd.Parameters.Add("@planttype", SqlDbType.NVarChar, 50);//性别 sp.Value = ""; if (ddlPlantType.SelectedValue != "0") { sp.Value = ddlPlantType.SelectedValue; } sp.Direction = ParameterDirection.Input; sp = cmd.Parameters.Add("@startdate", SqlDbType.NVarChar, 50); sp.Value = "1990-01-01"; if (txtStartDate.Text != string.Empty) { sp.Value = txtStartDate.Text; } sp.Direction = ParameterDirection.Input; sp = cmd.Parameters.Add("@enddate", SqlDbType.NVarChar, 50); sp.Value = "2020-11-01"; if (txtEndDate.Text != string.Empty) { sp.Value = txtEndDate.Text; } sp.Direction = ParameterDirection.Input; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "PlantType"); this.GvData.DataSource = ds; this.GvData.DataBind();
0 0
- sqlserver 临时表操作
- SqlServer 临时表操作
- SqlServer 临时表
- sqlserver 临时表使用方法
- sqlserver 临时表
- SQLServer的临时表
- SQLServer]临时表
- sqlserver创建临时表
- sqlserver 创建临时表
- sqlserver创建临时表
- sqlserver创建临时表
- sqlserver创建临时表
- sqlserver创建临时表
- SQLServer 临时表
- sqlserver 临时表
- SQLServer临时表与Oracle临时表
- 删除SQLSERVER中的临时表
- sqlserver 临时表应用 范例
- 简析POP3_IMAP_SMTP协议的区别_应用场景
- iOS开发~CocoaPods使用详细说明
- 一种全排列的方式
- Win8.1系统下 VS2010等版本中输入中文变问号的解决办法
- crm使用soap删除下拉框选项
- sqlserver 临时表操作
- mount
- hd 2055 An easy problem
- poj 1000
- ubuntu的一些必要设置
- POJ1287_最小生成树-Networking
- Java程序员们最常犯的10个错误
- 框架Spring的jar包下载
- C\C++语言中的计时函数