Results 1 to 6 of 6

Thread: Adding a word to existing value of a field

  1. #1
    Join Date
    Jul 2007
    Posts
    4

    Adding a word to existing value of a field

    Hi!
    I want to add a word to a value if the value already exists in that field. How to do this? Please help me. In detail, i have 'id', 'name' and 'info' three columns in one Data Table. When I inserted one value to id field, if the value already exists it should add a word to that value and it should get inserted. Please help me to do this?
    Thanks in advance!

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Can you give an example, it is not clear where you want to add word?

  3. #3
    Join Date
    Jul 2007
    Posts
    4
    thanks for your response skhanal, in 'id' field there are three values like 'suresh', 'madhivanan' and 'someone'. if i tried to insert 'suresh' again into the id field it should add '-rev' word to 'suresh' and it should save in the field as 'suresh-rev'. i hope this is what you asked me.

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    Use update statement like:

    update tab_name set id = 'suresh-rev' where id = 'suresh'

  5. #5
    Join Date
    Dec 2004
    Posts
    502
    IF EXISTS (SELECT 1 FROM YourTable WHERE id = @YourInsertedId)
    BEGIN
    UPDATE YourTable SET id = id + '-rev' WHERE id = @YourInsertedId
    END
    ELSE
    BEGIN
    INSERT INTO YourTable (id, name, info) VALUES(@YourInsertedId, @YourName, @YourInfo)
    END

  6. #6
    Join Date
    Jul 2007
    Posts
    4
    Thanks nosepicker and rmiao, my problem solved.

Posting Permissions

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