April 5, 2013 at 3:27 am
Hi,
how do I Concatenate fields by specifying the start position of the next filed.
e.g. I have table_x with three columns
Name
LastName
Empno
I would like to concatenate the three so that I only get one line. but I would also like to specify the length of the column and where the next column would start.
April 5, 2013 at 3:41 am
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
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
April 5, 2013 at 4:13 am
Thanks chris
that's it
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply