Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Database > Database General Discussion

Database General Discussion General discussion on database related topics

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-14-2008, 12:20 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 46
Posts: 52
Reputation: 20
victor64 is on a distinguished programming path ahead
Default How to insert "-" in existing records

Hello, I am using VB.NET 2005 and MS ACCESS 2003

My database contains data in the following format:

1305000248767

I need to insert "-" in several location to obtain the following format

1305-00-024-8767

How do I append the records to insert the "-" at these locations.

Thanks,

Victor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-14-2008, 8:58 AM
JuggaloBrotha's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jun 2004
Location: Lansing, MI; USA
Age: 25
Posts: 3,635
Reputation: 396
JuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NET
Default

Pull the data out as a string, then re-assign the string using .SubString() to insert the hyphen(s) in the correct places. For Example:
Code:
Dim myString As String = "123456"
myString = myString.SubString(0I, 3I) & "-" & myString.SubString(3I, 3I)
'myString is now "123-456"
__________________
Currently using: VS 2005 & 2008 Pro w/sp1 on Win7 Ultimate x64.


There are 3 kinds of people in the world: Those who can count and those who can't.
4 out of 3 people have trouble with fractions.

Windows has a 64 bit GUI for a set of 32 bit extensions on a 16 bit shell for an 8 bit OS using a 4 bit kernel made by a 2 bit company that can't stand 1 bit of competition.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-14-2008, 9:06 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 46
Posts: 52
Reputation: 20
victor64 is on a distinguished programming path ahead
Default How to insert "-" in field data

Hello,

Thanks for your reply, I'm afraid I can't assign mystring to a field value.
Do you have another approach?

This is what I have so far, but can't figure out the mySQL_Statement, or perhaps I need to use a For Next stament to go over each record??

Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\aopt2002orgorg.mdb;Persist Security Info=True;Jet OLEDBatabase Password=testaopupdate"
Dim objConnection As New OleDb.OleDbConnection(ConnectionString)

'data adapter
Dim objDataAdapter As New OleDb.OleDbDataAdapter(mySQL_Statement, objConnection)

'dataset object
Dim objDataSet As New DataSet
'fill dataset
objConnection.Open()
objDataAdapter.Fill(objDataSet, "SN")
objConnection.Close()

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-14-2008, 10:43 AM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 877
Reputation: 500
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

I'd use the substring function for T-SQL. Here's an example of formatting a social security number.

Code:
SELECT SUBSTRING(emp_ssn, 0, 3) + '-' + SUBSTRING(emp_ssn, 4, 2) + '-' + SUBSTRING(emp_ssn, 6, 4) AS SSN
FROM employee_table
I believe (don't use Access) that instead of SUBSTRING you use MID (same parameters) and '&' to concatenate rather than '+'.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-14-2008, 11:27 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 46
Posts: 52
Reputation: 20
victor64 is on a distinguished programming path ahead
Default

Matt,

Thanks for your input, I believe SSN will be a new field created automatically. I was able to make the conversion, but the code I used was much longer, I will also try it with your code.

I initially made a mistake the data in the field didn't have the first 4 characters, basically it was in two separate fields:

Field 1: 1340 and Field 2: 001188989, I modified the code to obtain 00-118-8989

Now I need to do a check with a second table which contains

1340-00-118-8989(1)
1305-00-198-8989
1340-00-118-8989(1)
1315-00-108-7777
etc...

How do I start my search after the fifth position to check against data in the table which contains the 00-118-8989 format and only take into consideration the 11 chatracters ( will also need to avoid the (1) data from the other table).

I propbably should open a new thread, but since you're familiar with what I'm trying to do, I thought it would be easier to get some feedback.

Thanks,

Victor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-14-2008, 3:22 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 877
Reputation: 500
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

You want to use these 2 values to do a JOIN on the tables?

Code:
SELECT *
FROM TableA a JOIN TableB b ON MID(a.column, 5, 11) = b.column
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-14-2008, 5:10 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Age: 46
Posts: 52
Reputation: 20
victor64 is on a distinguished programming path ahead
Default Searching for data to display from two tables a link field.

How would you use this statement with a where clause?
I will search the tables bases on values entered in a textbox.

Thanks,

Victor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 5:41 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.