How do I show the output like (2000,2001)

  • Hi

    I have years value populating as below:

    SELECT @Years = (SELECT STUFF((SELECT ', ' + [Year] FROM (SELECT [Year] FROM #Years) AS T FOR XML PATH('')),1,1,''))

    How do I show the output like this : (2000,2001)

    Thanks

  • declare @Years table (ccyy varchar(4));

    insert into @Years values (2010);

    insert into @Years values (2011);

    insert into @Years values (2012);

    declare @Y varchar(max);

    SET @Y = '('+(SELECT STUFF((SELECT ', ' + ccyy FROM (SELECT ccyy FROM @Years) AS T FOR XML PATH('')),1,1,''))+')'

    print @y;

  • I have already a table where the years gets inserted and I would like to parse it to show like this: (2000,2001)

    CREATE TABLE #Years (Year varchar(6))

    INSERT #Years

    (Year)

    SELECT '''' + CAST(Node.query('text()') AS varchar(100)) + '''' as YEAR

    FROM @XMLSelectedYears.nodes('/Years/*/YYYY') tempxml (Node);

    TIA

  • One more thing I need to add that in the #year table, the years get inserted like this:

    '2000', '2001','2002'

    All I need to do is to take out the tick around the year as below:

    2000,2001,2002

  • Can I use REPLACE function to get rid of quotation mark around the year

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

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