How to concatenate two strings in SQL Server 2005

后端 未结 6 1315
夕颜
夕颜 2020-12-06 09:16

I want to concatenate the words \"dummy\'s\" and \"dock\".

How can I concatenate them in SQL Server 2005? Does it support double quotes?

6条回答
  •  眼角桃花
    2020-12-06 09:37

    Try this:

    DECLARE @COMBINED_STRINGS AS VARCHAR(50); -- Allocate just enough length for the two strings.
    
    SET @COMBINED_STRINGS = 'rupesh''s' + 'malviya';
    SELECT @COMBINED_STRINGS; -- Print your combined strings.
    

    Or you can put your strings into variables. Such that:

    DECLARE @COMBINED_STRINGS AS VARCHAR(50),
            @STRING1 AS VARCHAR(20),
            @STRING2 AS VARCHAR(20);
    
    SET @STRING1 = 'rupesh''s';
    SET @STRING2 = 'malviya';
    SET @COMBINED_STRINGS = @STRING1 + @STRING2;
    
    SELECT @COMBINED_STRINGS; 
    

    Output:

    rupesh'smalviya

    Just add a space in your string as a separator.

提交回复
热议问题