473,790 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stored Procedure Help For Join Query

16 New Member
Hello members,

This is the SQL SERVER 2005 stored procedure.


It contains the data from the two diff tables.
(1)Customer :
Here clpid and cardid are composite primary keys with the identity field.It has storeid as foreign key.
The cardid is to be autogenerated everytime as the new customer is inserted.

I have to put the validations for the
* joindt = currentdate/todaydate
* dob is not greater than today date
* anniverdt is not less than equal to dob (in terms of year)

(2)Store :
Here storeid is the primary key.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. ALTER PROCEDURE CustomerStoredProcedure
  4.  
  5. @cardid INT OUTPUT,
  6. @clpid INT OUTPUT,
  7. @storename varchar(20),
  8. @firstname varchar(20),
  9. @lastname varchar(20),
  10. @joindt datetime,
  11. @anniverdt datetime,
  12. @dob datetime,
  13.  
  14. @frmErrorMessage AS VARCHAR(256) OUTPUT,
  15. @RETURNVALUE AS INT OUTPUT,
  16. @RETURNID AS INT OUTPUT
  17. AS
  18.  
  19. DECLARE
  20.  
  21.   @storeid AS INT
  22.  
  23. BEGIN
  24. SET NOCOUNT ON
  25.  
  26.  
  27. --validation...
  28. IF ( @firstname IS NULL OR @firstname = '' ) 
  29.     BEGIN
  30.         SET  @RETURNVALUE = -9
  31.         SET  @frmErrorMessage = 'FName is empty'
  32.         RETURN -9                        
  33.     END 
  34. IF ( @lastname IS NULL OR @lastname = '' ) 
  35.     BEGIN
  36.         SET  @RETURNVALUE = -9
  37.         SET  @frmErrorMessage = 'LName is empty'
  38.         RETURN -9                        
  39.     END
  40.  
  41. if  @DOB<@AnniversaryDate
  42.                 begin
  43.                     Select @frmErrorMessage ="AnniversaryDate cannot be greater then DOB"
  44.                     return -9
  45.                 end 
  46.             if  @DOB=@AnniversaryDate
  47.                 begin
  48.                     Select @frmErrorMessage ="AnniversaryDate cannot be equal to DOB"
  49.                     return -9
  50.                 end 
  51.  
  52.             if  @DOB>=getdate()
  53.                 begin
  54.                     Select @frmErrorMessage ="DOB cannot be greater then Today's Date"
  55.                     return -9
  56.                 end          
  57. BEGIN            
  58. IF EXISTS (select * from storemaster where storename = @storename)                                  
  59.        select @storeid = storeid from storemaster where storename = @storename                                                                                     
  60.  
  61.  
  62. IF EXISTS ( SELECT firstname,lastname,joindt,anniverdt,dob,
  63.                  FROM customermaster WHERE clpid = @clpid and cardid=cardid) 
  64.     BEGIN
  65.         UPDATE customermaster
  66.         SET firstname = @firstname,
  67.             lastname = @lastname,
  68.             storeid=@storeid,
  69.             joindt=@joindt,    
  70.             anniverdt=@anniverdt,
  71.             dob=@dob,
  72.  
  73.     WHERE  clpid= @clpid and cardid=@cardid
  74.  
  75.         SET  @frmErrorMessage = 'Name and other information has been updated'
  76.         SET @RETURNVALUE = 2
  77.     END
  78. END    
  79.  
  80. BEGIN
  81.    IF EXISTS (select * from storemaster where storename = @storename)                                  
  82.        select @storeid = storeid from storemaster where storename = @storename                                                                                     
  83.  
  84.  
  85.   IF NOT EXISTS(Select firstname,lastname,address 
  86.             from customermaster
  87.             where firstname = @firstname,lastname=@lastname)
  88.         BEGIN
  89.            INSERT INTO customermaster (firstname,lastname,joindt,anniverdt,dob,introducedby)
  90.                VALUES     (@firstname,@lastname,@joindt,@anniverdt,@dob,@introducedby)
  91.            SELECT @clpid = SCOPE_IDENTITY()
  92.            SELECT @cardid= SCOPE_IDENTITY()
  93.         END
  94.    ELSE
  95.        BEGIN
  96.           Print 'Name already exists'  
  97.        END
  98.  
  99.         SET  @frmErrorMessage = ' Name and other information has been Inserted'
  100.         SET @RETURNVALUE = 1
  101. END
  102.  
  103. SET NOCOUNT OFF
  104. END
  105.  
  106.  
Pls can anyone checkout my stored procedure as i have created for the first time for the join stored procedure.
It gives me the error but i can't rectify it.
It is too big but can anyone help then it's fine....
I have mentioned how i created my above procedure.
Can anyone also help me to check or put the validations for the date..

Thanxs in advance...waiti ng for solution

Hope to get a suitable reply
May 5 '07 #1
0 1724

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6706
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
10
3747
by: Thomas R. Hummel | last post by:
I have a stored procedure that suddenly started performing horribly. The query plan didn't look right to me, so I copy/pasted the code and ran it (it's a single SELECT statement). That ran pretty well and used a query plan that made sense. Now, I know what you're all thinking... stored procedures have to optimize for variable parameters, etc. Here's what I've tried to fix the issue: 1. Recompiled the stored procedure 2. Created a new,...
2
2334
by: jaYPee | last post by:
I have an existing query from MS Access that I want to convert it to SQL Server Stored Proc. My problem is on how to convert the WHERE clause. This is the query from MS Access: SELECT SchYrSemCourseJoin.SchYrSemCourseID, Students.IDNo, & ", " & & " " & AS Name, Program.ProgramTitle, Program.ProgramDesc, SchYrSem.SchYr, SchYrSem.Sem, SchYrSem.Year, SchYrSem.Section AS Section1,
7
9228
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into a table (c) re-queries another table using a subquery which references the inserted table (correlated or not)
28
72563
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
3
2167
by: Simon | last post by:
I have a problem using a stored procedure in C#. Im using SQL2000 and C# with web parts. Currently i put the entire sql query in the CommandText. Then it works correctly and gives the companynames in my column. As u can see below in the C# code. I made a Stored Procedure from the query and want to call that instead, it saves a lot of code in my project.
9
2469
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
6
5094
by: yin_n_yang74 | last post by:
I am trying to create a report in Crystal Reports (v 8.5). I have a stored procedure to pull data from two databases and parameters. There are multiple one-to-many relationships and the stored procedure returns duplicates; e.g., one schedule may have multiple resources, supplies, and/or orders (and one order may have multiple foods). Is there a way to stop the duplication? The stored procedure looks like this: ...
12
4714
by: brwalias | last post by:
Hi, using .net 2 sql server 2005 Here is my situation: I'm passing a variable in the url from a selection on Page A and need to display the results on the Results page be based on that variable in the url. I would like that variable to trigger a stored and
4
3379
by: aCe | last post by:
hi all, i need to convert these simple PHP code into stored procedure : <?php $result = mssql_query( "SELECT whid, whcode FROM warehouse" ); while( $wh = mssql_fetch_object( $result ) ) { $result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid = '" . $wh->whid . "'"; while( $pl = mssql_fetch_object( $result ) ) {
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.