Solved

Change the productID of my entire Product table according to clients changing ranking

Posted on 2011-03-10
3
326 Views
Last Modified: 2012-05-11
My web app presents an entire category of products displayed using (ORDER BY Product.ProductID).  My client wants to choose which products are side by side and/or at the top of the page. To add a Rank column to my product table would force the client to manually assign an integer to each product in his catalog. I am thinking there is a way to change the ProductID to accommodate him instead. Some way of reordering the table.  If anyone can help by either suggesting code or just tell me I am wasting my time, please do.
0
Comment
Question by:pathfinder8008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
ID: 35098047
There's probably a better solution. If the product ID is only used in the one table, then this might be doable without it being a major pain. If you have to update orders, etc. you're running the risk of corrupting data or, at best, having a lot of data to update. The other problem comes in when you add in more products. If you already have product 1, 2, and 3 and the customer wants to put 4 in between 1 and 2 you'll have to renumber again.

What about using your Rank idea, but with a modification? By default, rank is Null. In your query, you can do IsNull(Rank, 999999) (or some other large number). Then sort by Rank, ProductID. Anything with Null will show up at the end.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35098140
you shouldn't mess about with ID. The ID is there to uniquely identify each record, if you want to force an particular order then you would be better with a separate column to accomodate that.
0
 

Author Closing Comment

by:pathfinder8008
ID: 35099381
Thanks quizwedge, I added the Rank column and used (ORDER BY IsNull(Rank, 9999), Product.ProductID) to my SELECT ROW_NUMBER() and it works great. This solution will not over tax my client.  And yes, carl tawn you are absolutely correct about messing with the uniqueID. It was clutching at straws.  Thanks again to the pros at EE.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question