[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • 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

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

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