We have an old SQL table that was used by SQL Server 2000 for close to 10 years.
In it, our employee badge numbers are stored as char(6) from 000001 to 999999.
I am writing a web application now, and I need to store employee badge numbers.
In my new table, I could take the short cut and copy the old table, but I am hoping for better data transfer, smaller size, etc, by simply storing the int values from 1 to 999999.
In C#, I can quickly format an int value for the badge number using
public static string GetBadgeString(int badgeNum) { return string.Format("{0:000000}", badgeNum); // alternate // return string.Format("{0:d6}", badgeNum); } How would I modify this simple SQL query to format the returned value as well?
SELECT EmployeeID FROM dbo.RequestItems WHERE ID=0 If EmployeeID is 7135, this query should return 007135.
0s are significant to this field, why change it to anINTat all?FORMATfunction like C# :-)intvalues take up significantly less space thatchar(6), and there will be multiple of these entries per part that gets manufactured. Efficiency.DATALENGTH()) two bytes each. Since the column might be in an index, you could be saving more than 2MB. And with other columns added up, that 2 bytes might be just enough to reduce the length of a row enough to save a 4KB page per row. Is this going to be hosted on a mobile platform, or might you be focusing your attention in an unproductive area?