MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 28th, 2004, 03:31 PM
ndn_24_7 ndn_24_7 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 6 ndn_24_7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Converting nvarchar to int

Hello all,


I'm trying to convert a nvarchar datatype to int
(ie:1234-56-78 to 12345678) . These values are primary keys in two tables. Both these tables have 3500 rows of this key type. I want to convert this to a int so I can make it a AutoNumber primary key so I can increment it. Is this possible? If so, how do I do it. Do I need to delete the dashes first some how? I fairly new to database adminstration, so any guidance will be greatly appreciated.

Thank You

Last edited by ndn_24_7 : October 28th, 2004 at 03:48 PM. Reason: update example

Reply With Quote
  #2  
Old October 29th, 2004, 09:43 AM
annieko annieko is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Northampton, UK
Posts: 11 annieko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 9 m 52 sec
Reputation Power: 0
Have u tried first split it and then join it to get rid of the hyphens? Then maybe u'll be able to change it into int or numeric.

Reply With Quote
  #3  
Old November 9th, 2004, 05:12 PM
fbraun fbraun is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 307 fbraun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 4 m
Reputation Power: 0
you can do something like: newNumber = clng(replace(RS("KeyNum"), "-", ""))

This will remove the hyphens and convert the string into a number. However, you won't be able to write this (or any) number to an AutoNumber field, since that number is automatically incremented and supplied by the database itself.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Converting nvarchar to int


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT