Concatenated Values

  • I have this table

    CSN NAME LOCATION TYPE

    MO-550 IFA Comapny MO-450 SIPP

    1-275 BGT Company NN-SP Company

    1-2956 BLQ Company SSFT TRUST

    How do i write a query that returns a NAME concatenated with it's CSN

  • hoseam (8/31/2012)


    I have this table

    CSN NAME LOCATION TYPE

    MO-550 IFA Comapny MO-450 SIPP

    1-275 BGT Company NN-SP Company

    1-2956 BLQ Company SSFT TRUST

    How do i write a query that returns a NAME concatenated with it's CSN

    SELECT (CAST(tb.[NAME] AS VARCHAR(MAX)) + CAST(tb.[CSN] AS VARCHAR(MAX))) [result]

    FROM dbo.yourTable tb

    I have used VARCHAR(MAX) and explicit CASTs in the absence of a table definition.

    ---

    Note to developers:
    CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
    So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

    Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
    My blog: http://uksqldba.blogspot.com
    Visit http://www.DerekColley.co.uk to find out more about me.

  • The '+' operator does string concatenation in T-SQL. Assuming CSN and Name are both string columns in your table. You can:

    SELECT CSN + ' ' + [Name] AS CSNName

    FROM dbo.YourTable;

    HTH,

    Rob

  • Thank you guys

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply