Solved

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

Posted on 2011-03-10
3
320 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
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C# SQL BULK INSERT CLASS 5 34
Updating variable table 9 17
ASP.Net Session State alternatives 3 26
Asp.net mvc 5 5 16
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

707 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now