SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[jfac_WorkFlowMaintain]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[jfac_WorkFlowMaintain](
[AutoID] [int] IDENTITY(1,1) NOT NULL,
[CorpID] [varchar](10) NOT NULL,
[BillID] [varchar](30) NOT NULL,
[WorkBillID] [varchar](30) NOT NULL,
[FlowID] [varchar](15) NOT NULL,
[FlowName] [varchar](30) NOT NULL,
[BillDate] [datetime] NULL,
[Flag] [int] NOT NULL CONSTRAINT [DF_jfac_WorkFlowMaintain_Flag] DEFAULT (0),
[BillType] [varchar](10) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[jfac_WorkFlowSend]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[jfac_WorkFlowSend](
[AutoID] [int] IDENTITY(1,1) NOT NULL,
[CorpID] [varchar](20) NOT NULL,
[BillID] [varchar](25) NOT NULL,
[WorkBillID] [nchar](25) NOT NULL,
[FlowID] [varchar](20) NOT NULL,
[DatumType] [varchar](20) NULL,
[ItemID] [varchar](20) NULL,
[ItemName] [varchar](20) NULL,
[Line] [int] NOT NULL CONSTRAINT [DF_jfac_WorkFlowIncept_Line] DEFAULT (0),
[Weg] [float] NOT NULL CONSTRAINT [DF_jfac_WorkFlowIncept_Weg] DEFAULT (0),
[Qty] [int] NOT NULL CONSTRAINT [DF_jfac_WorkFlowIncept_Qty] DEFAULT (0),
[Shape] [varchar](70) NULL,
[Spec] [varchar](70) NULL,
[Price] [decimal](18, 2) NOT NULL CONSTRAINT [DF_jfac_WorkFlowIncept_Price] DEFAULT (0),
[Note] [varchar](200) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[syscontacts]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[syscontacts](
[LOGIC_NAME] [varchar](50) NOT NULL,
[PROVIDER_TYPE] [varchar](50) NOT NULL,
[CONNECTION_STRING] [varchar](255) NOT NULL,
[LOGIC_ONOFF] [bit] NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[gem_GetRecordPage]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
BEGIN
EXEC dbo.sp_executesql @statement = N'
/*
函数名称: gem_GetRecordPage
函数功能: 获取指定页的数据
参数说明: @tblName 包含数据的表名
@fldName 关键字段名
@PageSize 每页记录数
@PageIndex 要获取的页码
@OrderType 排序类型, 0 - 升序, 1 - 降序
@strWhere 查询条件 (注意: 不要加 where)
作 者: 王远洋
创建时间: 2005-05-01
修改时间: 2005-05-01
*/
CREATE PROCEDURE [dbo].[gem_GetRecordPage]
@tblName varchar(255), -- 表名
@fldName varchar(255), -- 字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(8000) = '''', -- 查询条件 (注意: 不要加 where)
@strGotFields varchar(1000) = ''*'' -- 需要返回的列
AS
declare @strSQL varchar(6000) -- 主语句
declare @strTmp varchar(1000) -- 临时变量
declare @strOrder varchar(500) -- 排序类型
if @OrderType != 0
begin
set @strTmp = ''<(select min''
set @strOrder = '' order by ['' + @fldName + ''] desc''
end
else
begin
set @strTmp = ''>(select max''
set @strOrder = '' order by ['' + @fldName +''] asc''
end
set @strSQL = ''select top '' + str(@PageSize) + @strGotFields + '' from [''
+ @tblName + ''] where ['' + @fldName + '']'' + @strTmp + ''([''
+ @fldName + '']) from (select top '' + str((@PageIndex-1)*@PageSize) + '' [''
+ @fldName + ''] from ['' + @tblName + '']'' + @strOrder + '') as tblTmp)''
+ @strOrder
if @strWhere != ''''
set @strSQL = ''select top '' + str(@PageSize) + @strGotFields + '' from [''
+ @tblName + ''] where ['' + @fldName + '']'' + @strTmp + ''([''
+ @fldName + '']) from (select top '' + str((@PageIndex-1)*@PageSize) + '' [''
+ @fldName + ''] from ['' + @tblName + ''] where '' + @strWhere + '' ''
+ @strOrder + '') as tblTmp) and '' + @strWhere + '' '' + @strOrder
if @PageIndex = 1
begin
set @strTmp = ''''
if @strWhere != ''''
set @strTmp = '' where ('' + @strWhere + '')''
set @strSQL = ''select top '' + str(@PageSize) + '' * from [''
+ @tblName + '']'' + @strTmp + '' '' + @strOrder
end
exec (@strSQL) |