Concatenating a string variable and a date variable into one string in SQL Server

Posted on 2012-08-17
Last Modified: 2012-08-17
Is there a way to concatenate two fields together in SQL Server using T-SQL into one string?
Question by:morinia
    LVL 65

    Accepted Solution

    Just use the plus sign

    SELECT 'goo ' + 'boo ' + 'foo'

    If the fields are anything other than characters, say numbers or dates, you have to convert them to characters in order to concatenate

    SELECT 'Right now it is ' + CAST(GETDATE() as varchar(max))

    SELECT 'Mambo Number ' + CAST(9 as char(1))
    LVL 65

    Expert Comment

    by:Jim Horn
    Thanks for the grade.  Good luck with your project.  -Jim

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now