update query

  • hi all, i have a table with a city column, i need to update the city like where city name is 'A' then it should be 'B' and when city name is

    'B' then it should be 'A'

  • Hi,

    Try this code..

    CREATE TABLE #IREMS (ItemID INT, City VARCHAR(20))

    INSERT INTO #IREMS (ItemID , City )

    SELECT 11, 'a' UNION ALL

    SELECT 22, 'b' UNION ALL

    SELECT 33, 'a' UNION ALL

    SELECT 44, 'hh' UNION ALL

    SELECT 55, 'b' UNION ALL

    SELECT 66, 'a'

    SELECT * FROM #IREMS

    UPDATE #IREMS SET City = CASE WHEN City='a' THEN 'b' WHEN City='b' THEN 'a' ELSE City END

    SELECT * FROM #IREMS

    DROP TABLE #IREMS

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

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