Page 1 of 3 123 LastLast
Results 1 to 15 of 45
  1. #1
    Join Date
    Aug 2007
    Posts
    17

    Unanswered: how to update single column

    hi guys i have a problem;;;

    i have to update table'''


    querey is--TABLE1 HAS A COLUMN CALLED CITY .THE RECORDS WITH CITY='DELHI' ARE IS TO BE UPDATED WITH CITY='MUMBAI' AND THE RECORDS WITH CITY='MUMBAI' ARE IS TO BE UPDATED WITH CITY='DELHI' ...

    i HAVE TO WRITE A SINGLE SQLSTATEMENT TO DO THIS NOT WITH THE HELP OF CURSOR

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    homework!!!!!

    sorry, we will not do your homework for you

    give it a try yourself and we will offer comments
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Here's a handy resource: www.w3schools.com/sql/default.asp
    George
    Home | Blog

  4. #4
    Join Date
    Aug 2007
    Posts
    17
    hi r397
    actually i had tried it many times ,in table there is only one column and set and where condition isto be applied on a single column simultaneously so iam not able to find the result...
    this is not a homework it is simply a task that isgiven to me by my friend.. please help me out


    table structure
    ----
    city
    ----
    delhi
    mumbai
    delhi
    mumbai


    i have to update delhi with mubai and mubai with delhi with single query not using cursor, i had done it bycursor but not be able to do this by a single query..

  5. #5
    Join Date
    May 2004
    Location
    bangalore
    Posts
    270
    will this solve ur purpose......???


    SELECT
    CASE CITYNAME
    WHEN 'delhi' THEN 'Mumbai'
    ELSE 'delhi'
    END
    FROM CITY


    Thanks,
    Rahul Jha

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no, dba_rahul, that will not do it

    "this is not a homework it is simply a task that isgiven to me by my friend.. please help me out"
    i will gladly tell you if your suggestion will work, but i am not going to just give you the answer
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    May 2004
    Location
    bangalore
    Posts
    270
    In Orackle this can be achived by the function called DECODE()

    UPDATE CITY
    SET
    CITYNAME =
    (
    DECODE(CITYNAME, 'Mumbai', 'delhi')
    )



    Thanks,
    Rahul Jha

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    rahul jha:

    1. that won't work in sql server (which is this forum)

    2. that won't work correctly in oracle anyway

    but thanks for trying
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    May 2004
    Location
    bangalore
    Posts
    270
    probably this might work then........ Its been ages that have worked in oracle..... hence no control on the syntax.......

    UPDATE CITY
    SET
    CITYNAME =
    (
    DECODE(CITYNAME, 'Mumbai', 'delhi', 'delhi', 'mumbai')
    )

    Quote Originally Posted by r937
    rahul jha:
    1. that won't work in sql server (which is this forum)

    I know that the forum is for SQL SERVER. Was just sharing the options that we don't have in SS. There are lot many people who visit the forum across the domain. My suggestion might be a help for them....



    Thanks,
    Rahul Jha

  10. #10
    Join Date
    Aug 2007
    Posts
    17
    thanks for trying

    but rahul this will not work...

    and for r937 if ur so good then answer it....!!!!!!

  11. #11
    Join Date
    May 2004
    Location
    bangalore
    Posts
    270
    As said, i hv a faded memory of oracle syntax......

    Quote Originally Posted by r937
    homework!!!!!

    sorry, we will not do your homework for you
    And vivek, I don't understand why people think that they have to react / respond to the all the queries even if they don't have the answer / or they don't want to answer. The forum doesn't compels any one to reply back once you read the query. But some people will never stop in their sarcastic replies.....

    Why do people poke their nose in each and every matter even though its not necessary.


    I guess this is the root cause of 90% global issues.


    Thanks,
    Rahul Jha

  12. #12
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by vivek_goel27
    and for r937 if ur so good then answer it....!!!!!!
    because it's homework!!

    let's see you try it!!!!!!
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  13. #13
    Join Date
    May 2004
    Location
    bangalore
    Posts
    270
    Quote Originally Posted by r937
    because it's homework!!

    let's see you try it!!!!!!
    The reason behind putting across the query to the forum is to get the suggestions / answer only. Atleast my understanding is this only.... Don't know what perception you have for the forum r937.......


    Quote Originally Posted by vivek_goel27
    i HAVE TO WRITE A SINGLE SQLSTATEMENT TO DO THIS NOT WITH THE HELP OF CURSOR
    Quote Originally Posted by vivek_goel27
    i have to update delhi with mubai and mubai with delhi with single query not using cursor, i had done it bycursor but not be able to do this by a single query..
    And mind it r937 that every one 1st tries from thier own only before putting across the query to the forum......

    Don't try to understimate / overestimate any one on the public forums...... If you know the answer please go ahead and answer or else you can opt to ignore it and just go through the threads to keep you updated.


    Thanks,
    Rahul Jha

  14. #14
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    If the OP would simply navigate to the link I posted and clicked on the "SQL Update" link then they'd have the answer already.
    George
    Home | Blog

  15. #15
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    um, george, i checked that link, and it doesn't give the mumbai/delhi example
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •