Wrox Programmer Forums
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP 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 December 22nd, 2006, 04:00 PM
Authorized User
Join Date: Dec 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stored Procedure

Can someone check to see if I creating this stored procedure correctly.
What I'm doing is passing customer zip to the procedure then looking up to see who is the sales rep in that area. I want to be able to return the reps name, address, city, state, phone and email

-- Drop Procedure if already exists
    IF OBJECT_ID('fn_salesrep_lookup_custzip') IS NOT NULL
      DROP PROC fn_salesrep_lookup_custzip

-- Create Procedure using temp variables as input variables

    CREATE Procedure fn_salesrep_lookup_custzip
        @CustomerZip Varchar(6)


           @Name nvarchar(50)
          ,@Address nvarchar(50)
          ,@City nvarchar(50)
          ,@State nvarchar(50)
          ,@Zip nvarchar(50)
          ,@Phone nvarchar(50)
          ,@email nvarchar(50);

  -- Get contact information
           @Name =LTRIM(RTRIM(T1.[SM-NAME]))
          ,@Address =LTRIM(RTRIM(T1.[SM-ADDRESS1]))+
                             WHEN ISNULL(T1.[SM-ADDRESS2],'')='' THEN ''
                             ELSE ', '+LTRIM(RTRIM(T1.[SM-ADDRESS2]))
          ,@City =LTRIM(RTRIM(T1.[SM-CITY]))
          ,@State =LTRIM(RTRIM(T1.[SM-STATE]))
          ,@Zip =CASE
                        WHEN LEN(LTRIM(RTRIM(T1.[SM-ZIP])))=6 AND LEFT(LTRIM(T1.[SM-ZIP]),1)='0' THEN RIGHT(RTRIM(T1.[SM-ZIP]),5)
                        ELSE LTRIM(RTRIM(T1.[SM-ZIP]))
          ,@Phone =LTRIM(RTRIM(T1.[SM-PHONE]))
          ,@email ='email not yet available'
        FROM dbo.SalesRep T1
           INNER JOIN dbo.SalesRepCustomerZip T2 ON T1.[SM-NBR]=T2.[SM-NBR]
                ELSE LTRIM(RTRIM(T2.ZIP))

        -- Return the information to the user
     IF @CustomerZip IS NOT NULL AND @Name IS NOT NULL

           SELECT @Name, @Address, @City, @State, @Zip, @Phone, @email


Old January 3rd, 2007, 12:29 AM
Authorized User
Join Date: Sep 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prabodh_mishra

Can you explain the problem you are confronting rather than putting us on analysis job?


Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure prashant_telkar SQL Server 2000 1 July 9th, 2007 07:57 AM
stored procedure kdm260 SQL Server 2000 2 June 19th, 2006 04:45 PM
Stored Procedure rajanikrishna SQL Server 2000 0 July 18th, 2005 05:01 AM
Help About Stored Procedure zhuge6 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 May 20th, 2005 09:27 AM
Stored Procedure help flyin SQL Server 2000 4 August 3rd, 2004 07:37 AM

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