• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Formatting values in two columns from one table to equal the values in one column using SQL VB

Table1
I have Column1 with values like 708-408
I have Column2 with values like 600

Table2
I have Column3 with values 708-408-600

I have a VB script logic that joins Table1 columns that equals Table2 Column3.

CAST([Column1] AS VARCHAR) + replace(str(CAST([Table1].[Column2] AS VARCHAR), 11),'',0) = [Table2].[Column3]

I want to know if the format in the first part CAST([Column1] AS VARCHAR) + replace(str(CAST([Table1].[Column2] AS VARCHAR), 11),'',0)  is the correct format so that it should exactly be in this format ###-###-###.






0
Jintonix415
Asked:
Jintonix415
1 Solution
 
Daniel WilsonCommented:
More like this:

CAST([Column1] AS VARCHAR) + '-' + right('000' + cast(column2 as varchar),3)

Open in new window

0
 
Jintonix415Author Commented:
It worked!!! Thanks!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now