Home Forums SQL Server 2008 T-SQL (SS2K8) Concatenate fields by specifying the start position of the next filed RE: Concatenate fields by specifying the start position of the next filed

  • Why don't you simply concatenate into fixed-width, like this?

    DROP TABLE #table_x

    CREATE TABLE #table_x (Empno INT IDENTITY(3141593,31415), FirstName VARCHAR(25), LastName VARCHAR(25))

    INSERT INTO #table_x (FirstName, LastName) VALUES

    (('Francis'),('Bacon')),

    (('Jean'),('Baptiste')),

    (('Clarence'),('Birdseye')),

    (('Charles'),('Babbage')),

    (('John'),('Logie Baird'))

    SELECT *,

    Concatenated_FixedWidth = CAST(FirstName AS CHAR(25)) + CAST(LastName AS CHAR(25)) + CAST(Empno AS CHAR(25))

    FROM #table_x

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden