Welcome to Dream.In.Code
Become an Expert!

Join 150,223 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,249 people online right now. Registration is fast and FREE... Join Now!




Can Anyone Help me with SQL Stored Procedures

 
Reply to this topicStart new topic

Can Anyone Help me with SQL Stored Procedures

pietervdl
11 Dec, 2007 - 12:04 AM
Post #1

New D.I.C Head
*

Joined: 9 Oct, 2007
Posts: 15


My Contributions
Hi,
I don't know where to post this Question.
Let me begin by telling you what I have.
I have got three tables in one database in sql.Each table is displayed via a datagrid in a web application I am busy with.
I also created a fourth Table for the deleted Items.
I want to create a stored procedure with sql script.
I want the stored procedure to check the data that was deleted from each table and display that deleted data in a fourth data grid in my web application.
Here is the stored Procedure.
Hope someone can help me.
Thanks

CODE

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'sp_DeletedItems')
    BEGIN
        DROP  Procedure  sp_DeletedItems
    END

GO

CREATE Procedure sp_DeletedItems
    @pint_ItemId int,
    @pnv_Type nvarchar(12)

AS
IF(@pnv_Type = 'Category')
    BEGIN

SELECT d.int_DeleteId, d.nv_CategoryName, d.nv_SubCategoryName, d.ntxt_Question, d.nv_UpdateUser, d.dt_LastUpdate, d.int_CategoryId, c.int_CategoryId, d.int_SubCategoryId, d.int_QuestionId
FROM tblDeletedItem d
    INNER JOIN tblCategories c
        ON d.int_CategoryId = c.int_CategoryId
ORDER BY d.dt_LastUpdate

    END

IF(@pnv_Type = 'Subcategory')
    BEGIN
SELECT d.int_DeleteId, d.nv_CategoryName, d.nv_SubCategoryName, d.ntxt_Question, d.nv_UpdateUser, d.dt_LastUpdate, d.int_CategoryId, s.int_SubCategoryId, d.int_SubCategoryId, d.int_QuestionId
FROM tblDeletedItem d
    INNER JOIN tblSubCategories s
        ON d.int_SubCategoryId = s.int_SubCategoryId
ORDER BY d.dt_LastUpdate

    END

IF(@pnv_Type = 'Question')
    BEGIN
SELECT d.int_DeleteId, d.nv_CategoryName, d.nv_SubCategoryName, d.ntxt_Question, d.nv_UpdateUser, d.dt_LastUpdate, d.int_CategoryId, q.int_QuestionId, d.int_SubCategoryId, d.int_QuestionId
FROM tblDeletedItem d
    INNER JOIN tblAssessmentQuestions q
        ON d.int_QuestionId = q.int_QuestionId
ORDER BY d.dt_LastUpdate

    END
    
GO

GRANT EXEC ON sp_DeletedItems TO PUBLIC

GO

User is offlineProfile CardPM
+Quote Post

Lord Hadies
RE: Can Anyone Help Me With SQL Stored Procedures
11 Dec, 2007 - 12:33 AM
Post #2

D.I.C Regular
***

Joined: 24 Nov, 2006
Posts: 307


My Contributions
Dude!!!you're capable of signing up, putting 14 posts, finding the lounge, even putting your qouting your code...why didn't you post your question in the DATABASE section???eish...its funny how people keeping putting posts wherever smile.gif
User is offlineProfile CardPM
+Quote Post

Trogdor
RE: Can Anyone Help Me With SQL Stored Procedures
12 Dec, 2007 - 06:06 AM
Post #3

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 549



Thanked: 4 times
Dream Kudos: 125
My Contributions
ok. what is your question.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:57AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month