Concatenating fields

  • Hi,

    I have a requirement to concatenate two fields together, however I cannot get the syntax of the code correct.

    I need to join field1 + '/' + field. I have tried :-

    CAST(FIELD1 AS varchar(10)) + '/' + FIELD2 As fulltext,

    Unfortunately this does not work.

    Any advice anyone?


    Kindest Regards,

    Nick

  • What are the data types of the 2 columns - can you give us sample data?

    What error do get ?

  • Hi,

    Thankyou for your reply, the fields are :-

     

    Field1, Field2

    23116,02 etc etc

    The output would need to be 23116/02.

     

    Thanks

     

     

     


    Kindest Regards,

    Nick

  • HI Nick,

     

    What are the data types of your fields?

     

    If they are both INT's then if you cast both of them to VARCHAR it should work 100%

     

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • HI,

    They field one is varchar, field two is int.

     


    Kindest Regards,

    Nick

  • HI Nick,

     

    Make sure that you cast Field2 to a varchar before trying to concatenate the fields.

    If both vars are varchars at the point on concatenating then it will def work.

     

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Field1 is already VARCHAR? And Field2 is INT?

    CAST(FIELD1 AS varchar(10)) + '/' + FIELD2 As fulltext,

    Field1 + '/' + CONVERT(VARCHAR, Field2) AS FullText

     


    N 56°04'39.16"
    E 12°55'05.25"

  • Spot on .... Thanks.


    Kindest Regards,

    Nick

Viewing 8 posts - 1 through 7 (of 7 total)

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