How to apply FindString method?

  • Hi folks,

    I have two database tables that stores routing informations of company vehicles. One of the table's data includes destination points and other stores full routing path.

    When I run a select statement  I got a result as below:

    ---------------------------------------

    SELECT * FROM ROUTES

    NY Store1 NY Store2

    LA Central Store

    -----------------------------------------

    SELECT * from DestinationPoints

    NY Store1

    NY Store2

    NY Store3

    LA Central Store

    -------------------------------------------

    How can I organize my "routes" table as data1;data2;data3 and so on.......

    SELECT * FROM Routes

    NY Store1;NY Store2;LA Central Store

  • This was removed by the editor as SPAM

  • Not quite sure what you are trying to achieve. 

    This should work and you could make it an UDF. 

     

    DECLARE @Routes TABLE( Location varchar(25))

    INSERT INTO @Routes

    SELECT 'NY Store1' UNION ALL

    SELECT 'NY Store2' UNION ALL

    SELECT 'LA Central Store'

        

    DECLARE @MultipleLocations varchar(500)

    SELECT @MultipleLocations = CASE @MultipleLocations

                                                            WHEN ''

                                                            THEN COALESCE( @MultipleLocations, '')

                                                            ELSE COALESCE( @MultipleLocations, '')

                                                 END  + Location + CHAR(59)

    FROM @Routes

    SELECT SUBSTRING( @MultipleLocations, 1, LEN( @MultipleLocations) - 1) AS '@MultipleLocations'

    I wasn't born stupid - I had to study.

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

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