Concatenating two values

  • I have two values @service and @office in a stored procedure. When the stored procedure is running @service has the value P and @office has the value L. I want to asssign PL to @temp.

    I have tried it the following way:

    @temp = @service + @office

    but the aove just gives @temp the value P, but does not add on the L.

    Any Ideas.

    Thanks,

    macca

  • As you will see if you run this piece of code, your method should work.

    declare @temp varchar(10), @service varchar(10), @office varchar(10)

    set @service = 'P'

    set @office = 'L'

    set @temp = @service + @office

    select @service service, @office office, @temp temp

    So there must be some other problem happening - what is @temp declared as?  You might have to post more of the code here.

    Regards, Phil

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • make sure you declare your [var]char variable with its size : varchar(SizeGoesHere). The default is 1 and I suspect that this is your problem.

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

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