UPDATE and REPLACE part of a string

前端 未结 10 2303
渐次进展
渐次进展 2020-12-04 04:22

I\'ve got a table with two columns, ID and Value. I want to change a part of some strings in the second column.

Example of Table:



        
相关标签:
10条回答
  • 2020-12-04 05:24

    query:

    UPDATE tablename 
    SET field_name = REPLACE(field_name , 'oldstring', 'newstring') 
    WHERE field_name LIKE ('oldstring%');
    
    0 讨论(0)
  • 2020-12-04 05:25
    CREATE TABLE tbl_PersonalDetail
    (ID INT IDENTITY ,[Date] nvarchar(20), Name nvarchar(20), GenderID int);
    
    INSERT INTO Tbl_PersonalDetail VALUES(N'18-4-2015', N'Monay', 2),
                                         (N'31-3-2015', N'Monay', 2),
                                         (N'28-12-2015', N'Monay', 2),
                                         (N'19-4-2015', N'Monay', 2)
    
    DECLARE @Date Nvarchar(200)
    
    SET @Date = (SELECT [Date] FROM Tbl_PersonalDetail WHERE ID = 2)
    
    Update Tbl_PersonalDetail SET [Date] = (REPLACE(@Date , '-','/')) WHERE ID = 2 
    
    0 讨论(0)
  • 2020-12-04 05:25

    replace for persian word

    UPDATE dbo.TblNews
    SET keyWords = REPLACE(keyWords, '-', N'،')
    

    help: dbo.TblNews -- table name

    keyWords -- fild name

    0 讨论(0)
  • 2020-12-04 05:26

    You have one table where you have date Code which is seven character something like

    "32-1000"
    

    Now you want to replace all

    "32-"
    

    With

    "14-"
    

    The SQL query you have to run is

    Update Products Set Code = replace(Code, '32-', '14-') Where ...(Put your where statement in here)
    
    0 讨论(0)
提交回复
热议问题