正在开发一款程序,遇到如下问题,求解决方法:
基本需求是将部门预算与实际发生进行对比分析
即:每月财务决算后,将每个部门的实际发生与预算比较,要求按部门,费用,预算的类别(半年预算,月别预算,年度预算),预算的月别,分别对比,我如何设计能很快捷地从数据库中抽取这些数,并输出?数据库设计有无特殊点?手机发帖格式没怎么排,求方法!

解决方案 »

  1.   

    一条一条查询肯定不如一次查询一批效率高.对要查询的字段酌情建立索引(过多的索引会影响数据写入效率)
    如果联合查询的结果集字段相对稳定, 可以建立视图, 并为视图加索引
    查询运算符最好不用或少用in, like等.
      

  2.   

    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]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