Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 22nd, 2006, 04:00 PM
Authorized User
Join Date: Dec 2005
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old January 3rd, 2007, 12:29 AM
Authorized User
Join Date: Sep 2003
Location: Delhi, Delhi, India.
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?

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 07:48 PM.

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