Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 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
 
Old February 28th, 2008, 07:30 AM
Authorized User
 
Join Date: Aug 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to zrtv
Default Number format in the table

Hi All,
I have one product table having the following field

pk_productID int,
descript nvarchar(50)

i want to format pk_productID field in the following number format
for example my product code will be
000001
000002

how i can achieve this task

Can somebody help meeee.....



 
Old February 28th, 2008, 08:13 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

I think you need to keep you column as varchar instead of int

urt

Help yourself by helping someone.
 
Old February 28th, 2008, 08:34 AM
Authorized User
 
Join Date: Aug 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to zrtv
Default

But in Msaccess we have an option called 'format' my doubt is , is ther any such format in sql server

 
Old February 28th, 2008, 10:42 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Is it vital to have the actual data in the database have these padded values? Or is it a concern more for display of the data? Is the latter, in what type of application/code are you displaying the data?

-Peter
peterlanoie.blog
 
Old February 28th, 2008, 11:59 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Yes... create a calculated column to display the data.

I have to agree with the others, though... storing formatted data in a table is "Death by SQL" and, no, this isn't Access.

--Jeff Moden
 
Old February 29th, 2008, 02:02 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Preethi Send a message via Yahoo to Preethi
Default

IF you want to display only once in a while, You can use it like this
SELECT RIGHT('000000'+CONVERT(varchar, pk_PRODUCTID), 6) AS ProductCode
Otherwise add an additional (Computed) column using the format. But it is not a recommended solution for a highly used production system.


G.R.Preethiviraj Kulasingham
 
Old March 7th, 2008, 03:18 AM
Authorized User
 
Join Date: Jun 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SELECT RIGHT('000000'+CONVERT(varchar, pk_PRODUCTID), 6) AS ProductCode
or change the column data type varchar







Similar Threads
Thread Thread Starter Forum Replies Last Post
Format Number Dink Classic ASP Databases 2 January 23rd, 2007 01:40 AM
Number Format - Need Help! bridog39 Access 7 November 14th, 2005 02:50 PM
Format Number hcweb Classic ASP Basics 4 October 27th, 2004 11:23 AM
format number tgopal Javascript 2 April 30th, 2004 03:44 AM
size of table (type table is table of number) MikoMax Oracle 1 November 19th, 2003 03:11 AM





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