Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| 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 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
  #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


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





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