Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2008, 07:30 AM
Authorized User
 
Join Date: Aug 2007
Location: MANAMA, MANAMA, Bahrain.
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.....



Reply With Quote
  #2 (permalink)  
Old February 28th, 2008, 08:13 AM
Friend of Wrox
 
Join Date: Oct 2007
Location: , , .
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.
Reply With Quote
  #3 (permalink)  
Old February 28th, 2008, 08:34 AM
Authorized User
 
Join Date: Aug 2007
Location: MANAMA, MANAMA, Bahrain.
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

Reply With Quote
  #4 (permalink)  
Old February 28th, 2008, 10:42 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #5 (permalink)  
Old February 28th, 2008, 11:59 PM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
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
Reply With Quote
  #6 (permalink)  
Old February 29th, 2008, 02:02 AM
Authorized User
 
Join Date: Jun 2003
Location: Colombo 04, WP, Sri Lanka.
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
Reply With Quote
  #7 (permalink)  
Old March 7th, 2008, 03:18 AM
Authorized User
 
Join Date: Jun 2007
Location: pune, Mah, India.
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


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:09 AM.


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