Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2007, 10:43 AM
Registered User
 
Join Date: Mar 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default NEED HELP TO MODIFY STORED PROCEDURE

Pls check my code for the stored procedure which i created for the companydetails including

companyid P.K. Not Null int(4),

companyname Not Null varchar (20),

address varchar(30)

where companyid is the primary key and it should be autogenerate.

I also want that it should check if the name exits or not.It should also check that the field is entered and not kept null.If it's null then should return the error message.

I want to write the queries select,insert,update and delete in the single stored procedure.

How can i differ all the query individually in a stored procedure.

The select and insert query are done on the button click event whereas the update,delete queries are performed in the gridview link event.

Pls help me and modify my code accordingly with ur suggestions who know the stored procedure very well.First read what i want then give reply.

waiting for the reply and with corrections.

The coding is perfomed in sql server 2005 and asp.net with C# 2005,
Code:
1    ALTER PROCEDURE CompanyStoredProcedure
2       @uspcompanyid int,
3        @uspcompanyname varchar(20),
4        @uspaddress1 varchar(30),  
5        @frmErrorMessage as varchar(256)  OUTPUT,
6        @RETURNVALUE as int OUTPUT,
7        @RETURNID as int OUTPUT
8    AS
9        declare
10         @companyid int,
11         @companyname varchar(20),
12         @address1 varchar(30) 
13         
14   BEGIN
15           
16           begin
17               Select @RETURNVALUE = -9
18               RETURN -9
19           end
20       
21           begin
22               Select @frmErrorMessage = 'The Operation Mode Has Not Been Specified'
23               return -9
24           end
25       
26           
27       
28           begin      
29                           --validation...
30                    if (@uspcompanyname is Null or @uspcompanyname = '')
31                       begin
32                           Select @RETURNVALUE = -9
33                           select @frmErrorMessage = 'Company Name is empty'
34                           return -9                        
35                   end     
36   
37                 if exists  (select companyid from companymaster 
38                             where upper(companyname) = upper(cast(@uspcompanyname as varchar(20))))
39                    begin
40                     select @companyid = companyid from companymaster 
41                            where upper(companyname)=upper(cast(@uspcompanyname as varchar(20) ) )
42                   end
43                else 
44                                       
45                   select @companyname    = cast (@uspcompanyname    as varchar(20))
46                   select @address1    = cast(@uspaddress1 as varchar(30))
47                   select @companyid = isnull(max(companyid),0) + 1 from companymaster    
48                    
49       IF exists(SELECT * from companymaster where  companyname=@companyname)
50            begin
51               Select @frmErrorMessage = 'Record With Company Name ' 
52                            + @companyname + ' is Already Exisiting For The Company Name ' 
53               return -9
54             end     
55                   
56                   -- the following codes inserts    
57           begin transaction
58               INSERT INTO companymaster
59                         ( companyname, address1)
60                   VALUES (@companyname,@address1)
61           commit transaction
62                       
63                   select @RETURNVALUE = 0
64                   select @RETURNID = @companyid        
65                               
66           end    
67                           
68         
69                   -- the following codes edit/updates
70           begin    
71               UPDATE companymaster 
72               SET companyname=@companyname,
73                   address1=@address1         
74               WHERE companyid =cast(@uspcompanyid as int)
75                                   
76                   select @RETURNVALUE = 0
77                   select @RETURNID = cast(@uspcompanyid as int)
78            end
79                      -- the following codes delete
80               begin
81                  DELETE companymaster WHERE (companyid = @companyid)
82               end   
83            
84    END 
85

Pls help me and modify my code accordingly with ur suggestions who know the stored procedure very well.First read what i want then give reply.



 
Old April 3rd, 2007, 01:31 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't want to sound rude or unfriendly, but I think this won't work:
Quote:
quote:Pls help me and modify my code accordingly with ur suggestions who know the stored procedure very well.First read what i want then give reply.
We are not your on-line debugger. You can't just tell people to fix your problems for you, without showing you've put some time in this yourself.

It seems that you're missing some fundamental knowledge to perform the task you're asked to do. This is not a problem; there are many books and on-line resources available that will help you understand your tasks better. However, in order to achieve that, you'll need to read, Google and read some more. Wrox has a number of good books on SQL Server that deal with T-SQL and stored procedures. Do yourself a favor and get one of those.

Additionally, use Google to query for parts of your problem, and you'll be surprised at the results you get.

You can always come back to this forum to ask for specific help on specific problems. You just can't expect us to do your work for you.

To get a detailed version of what I just said, take a look here: http://www.catb.org/~esr/faqs/smart-questions.html

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old April 3rd, 2007, 04:29 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Already asked here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81615


 
Old April 9th, 2007, 01:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Looks like this has been posted all over the world.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure prashant_telkar SQL Server 2000 1 July 9th, 2007 07:57 AM
This Stored Procedure rao965 SQL Server 2000 2 July 2nd, 2007 07:21 PM
stored procedure keyvanjan Classic ASP Basics 6 August 1st, 2006 07:42 AM
Help On Stored Procedure desireemm SQL Language 2 October 31st, 2005 07:11 PM
Stored Procedure bmains SQL Server ASP 2 October 8th, 2004 03:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.