-
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!
-
Can you give an example, it is not clear where you want to add word?
-
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.
-
Use update statement like:
update tab_name set id = 'suresh-rev' where id = 'suresh'
-
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
-
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
-
Forum Rules
|
|