Document Saving in Database
----------------------------
Table Structure
---------------
CREATE TABLE [dbo].[eDocuments](
[DownloadID] [int] IDENTITY(1,1) NOT NULL,
[DocTitle] [varchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[DocStream] [image] NULL,
[DocExt] [varchar](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DocSize] [float] NULL,
[DocType] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Decription] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ReviewDate] [datetime] NULL DEFAULT (getdate())
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
Procedure for Saving Document Data into Database
-------------------------------------------------
CREATE PROC [dbo].[eDocumentsUPD]
(
@DownloadID INT=0,
@DocTitle VARCHAR(200),
@DocStream IMAGE,
@DocExt VARCHAR(5),
@DocSize FLOAT,
@DocType VARCHAR(25),
@Decription VARCHAR(500)=NULL
)
AS
DECLARE @RECORDCOUNT INT
SET @RECORDCOUNT=0
SELECT @RECORDCOUNT=COUNT(*)
FROM eDocuments
WHERE DownloadID=@DownloadID
IF @RECORDCOUNT=0
BEGIN
INSERT INTO eDocuments
(
DocTitle,DocStream,DocExt,DocSize,DocType,Decription ,ReviewDate
)
SELECT @DocTitle,@DocStream,@DocExt,@DocSize,@DocType,@Decription ,GETDATE()
Select @DownloadID=IDENT_CURRENT('eCtblDownloadableDocuments')
END
ELSE
BEGIN
UPDATE eDocuments
SET DocTitle=DocTitle,
DocStream=DocStream,
DocExt=DocExt,
DocSize=DocSize,
DocType=DocType,
Decription= Decription ,
ReviewDate=GETDATE()
WHERE DownloadID=DownloadID
END
select @DownloadID as DownloadID
IF @@error!=0
BEGIN
RAISERROR 20001 'eDocumentsUPD: Failed Insert/Updae Records Into eDocuments'
RETURN(1)
END
RETURN(0)
Stored Procedure for Getting Documents Info Based on DocumentID
---------------------------------------------------------------
CREATE PROC [dbo].[eDocumentsGETByID]
@DownloadID int
AS
SELECT
ISNULL(DownloadID,0) AS DownloadID ,
ISNULL(DocTitle,'') AS DocTitle,
DocStream,
ISNULL(DocExt,'') AS DocExt,
ISNULL(DocSize,0) AS DocSize,
ISNULL(DocType,'') AS DocType,
ISNULL(Decription,'') AS Decription ,
ReviewDate
FROM eDocuments
where DownloadID=@DownloadID
Monday, July 6, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment