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

Posted on 2011-10-05
Last Modified: 2012-05-12
I have Column1 with values like 708-408
I have Column2 with values like 600

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 ###-###-###.

Question by:Jintonix415
    LVL 32

    Accepted Solution

    More like this:

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

    Open in new window


    Author Closing Comment

    It worked!!! Thanks!!!

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now