Delphi 调用SQL Server 2008存储过程2
2022/2/3 19:14:24
本文主要是介绍Delphi 调用SQL Server 2008存储过程2,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.表结构如下(预算数据明细表):
CREATE TABLE [dbo].[BA_FeeDetail]( [ID] [int] IDENTITY(1,1) NOT NULL, [FeeDeptID] [nvarchar](4) NULL, [FeeDate] [int] NULL, [FeeCode] [nvarchar](10) NULL, [FeeType] [nvarchar](1) NULL, [BAType] [nvarchar](1) NULL, [FeeAmt] [float] NULL ) ON [PRIMARY]
2.创建存储过程(用于取得某部门某次预算的某月某费目的预算额)
CREATE PROCEDURE [dbo].[GetBudgetAmt] -- Add the parameters for the stored procedure here @DeptID nvarchar(4) = '7120', @FeeDate int = 201301, @FeeCode nvarchar(8) ='31301' , @FeeType nvarchar(1) = '2', @BAType nvarchar(1)='1', @FeeAmt float output AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT @FeeAmt = FeeAmt from BA_FeeDetail where ( FeeCode = @FeeCode and FeeType = @FeeType and FeeDate = @FeeDate and FeeDeptID = @DeptID and BAType = @BAType ) Return @FeeAmt END
3.delphi 程序中调用(使用ADOConnect 和 ADOStoreProc )
procedure TForm1.btn1Click(Sender: TObject); Var BudgetAmt:Single; begin with ADOSP1 do begin ProcedureName :='GetBudgetAmt'; Parameters.Refresh; //必须有本语句,刷新参数 Parameters.ParamByName('@DeptID').Value:=EdtDept.Text; Parameters.ParamByName('@FeeDate').Value:=EdtFeeDate.Text; Parameters.ParamByName('@FeeCode').Value:=EdtFeeCode.Text; Parameters.ParamByName('@FeeType').Value:=EdtFeeType.Text; Parameters.ParamByName('@BAType').Value:=EdtBAType.Text; Parameters.ParamByName('@FeeAmt').Value:=0.00; ExecProc; BudgetAmt:=Parameters.ParamByName('@FeeAmt').Value; edtFeeAmt.Text:=Format('%.2f',[BudgetAmt]); end; end;
这篇关于Delphi 调用SQL Server 2008存储过程2的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-08Docker下的SqlServer发布订阅启用
- 2023-06-05Docker安装MS SQL Server并使用Navicat远程连接
- 2023-05-25深入浅出 SQL Server CDC 数据同步
- 2023-05-12通过空间占用和执行计划了解SQL Server的行存储索引
- 2023-04-24以SQLserver为例的Dapper详细讲解
- 2022-11-30SQL server高级函数查询
- 2022-11-26SQL SERVER数据库服务器CPU不能全部利用原因分析
- 2022-11-21SQL Server 时间算差值/常用函数
- 2022-11-20调试Archery连接SQL Server提示驱动错误
- 2022-10-22SQL Server 完整、差异备份+完整、差异还原(详细讲解,规避错误)