Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 20th, 2008, 05:31 AM
Registered User
 
Join Date: Feb 2008
Location: gurgoan, Hariyana, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to krshekhar Send a message via Yahoo to krshekhar
Default store procedure if else problem

i am writing a store procedure for rearranging the homepagedisplay order for an item in the item table as follows


create PROCEDURE sp_resetItemOrder(@oldOrder int, @newOrder int,@itmeId int)
as
declare @maxId int
IF @oldOrder=@newOrder/*IF THE OLD AND NEW ORDER ARE SAME*/
   return
else
if @newOrder=0/*IF THE NEW HOME PAGE ORDER IS 0 */

   begin
     update item set Item_HomePageorder=0 where item_Key=@itmeId
     update item set Item_HomePageorder=Item_HomePageorder-1 where Item_HomePageorder>@oldOrder
   end

else /*IF THE HOME PAGE ORDER IS NOT 0 */
  begin

    set @maxId=(select isnull(max(Item_HomePageorder),1) from item) /*SELECT THE MAX ITME HOME PAGE ORDER*/

   if @newOrder>=@maxId /*IF THE NEW ORDER IS GREATER THAN MAX ID */
      begin
       update item set Item_HomePageorder=Item_HomePageorder-1 where item_HomePageOrder between @oldOrder+1 and @maxId-1
       update item set Item_HomePageorder=@maxId where item_Key=@itmeId
      end
  else
    begin
      if @oldOrder>@newOrder
       begin

        update item set Item_HomePageorder=Item_HomePageorder+1 where Item_HomePageorder between @newOrder and @oldOrder-1
        update item set Item_HomePageorder=@newOrder where Item_Key=@itmeId
      end

     else
      begin
        update item set Item_HomePageorder=Item_HomePageorder-1 where Item_HomePageOrder>@oldorder and Item_HomePageorder<=@newOrder
        update item set Item_HomePageorder=@newOrder where Item_Key=@itmeId
      end

   end

  end


but it is not working properly
can any one sugges me whee i am wrong

SHEKHAR
Reply With Quote
Reply


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
Problem with clause Top in store procedure Javierera SQL Server 2005 3 October 24th, 2008 10:17 AM
Store procedure help... RinoDM SQL Server 2000 7 August 11th, 2008 07:09 PM
Store procedure help ??? RinoDM SQL Server 2000 8 May 1st, 2008 03:03 PM
Store Procedure sureshyuga SQL Server 2000 0 May 18th, 2007 01:49 AM
Store Procedure Problem jazzcatone ASP.NET 2.0 Basics 3 March 28th, 2006 12:41 AM



All times are GMT -4. The time now is 08:18 PM.


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