SQL query to concatenate results

  • Dear All,

    SQL Server 2000.

    I have a configuration table with just two columns: LogicalName and PhysicalName. I have two rows in this table (there are more, but 2 that I care about right now) where I'd like to concatenate the value in the PhysicalName table to make one string.

    For example:

    LogicalName PhysicalName

    "Working Directory" "c:\"

    "File Name" "test.txt"

    Can I make a SELECT query that will come up with a result like:

    FileLocation: "c:\test.txt"

    I hope this will work. If I can't do this, I will have to stick the directory name in all of the various file name rows. I have a lot of them. Then if we ever change the directory we work from, I will have to change all those rows.

    Thanks.

    Lisa

  • The '+' operator performs string concatenation.

    The CROSS JOIN join operator gives you the required resultset.

    SELECT t1.PhysicalName + t2.PhysicalName

    FROM YourConfigTable As t1

    CROSS JOIN YourConfigTable As t2

    WHERE t1.LogicalName = 'Working Directory'

    AND   t2.LogicalName = 'File Name'

     

  • THANK YOU THANK YOU THANK YOU

    Man I feel like I tried everything but that.

    Here's a nice picture I took of a bee and some blossoms. You can make it a wallpaper or something. My way of thanking you. http://community.webshots.com/photo/548346615/2123165060060632023nSduAd

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

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