Need help to Concatenate in a Stored Procedure

  • I hope someone can help me with this. I'm trying to do some concatenation in a stored procedure. I have in an Access query this string.

    MyAACol: "AA" & [Org] & "00" & [Acct_Nbr] & [Tran_Code] & [Amount]

    The variables "AA" and "00" are not actual fields in the table but text I want to include in the string. The name of the field wil be MyAACol. How this same thing be accomplished in a stored procedure?  

  • "+" is the string concatenation operator in T-SQL.  If the table columns aren't character, you'll have to CAST them.

    Greg

    Greg

  • Also, you want to use single quotes instead of double quotes.

    So, assuming Tran_Code and Amount are numeric data types and the others are not:

    ('AA' + [Org] + '00' + [Acct_Nbr] + CAST([Tran_Code] as varchar(10)) + CAST([Amount] as varchar(30)) ) AS MyAACol

  • and null ''

    null + 'any string' = null

    you will have to use the ISNULL() function which is simillar to the NZ() function in ACCESS.

    ISNULL(null,'') + 'any string' = 'any string'

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

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