Frog Frog Recommended: Solution to Several Field Conversion Problems of Database

xiaoxiao2021-03-06  21

Frog Frog Recommendation: Solution of several field conversion problems of the database Because the newly developed software needs some of the data generated by some old software, it is not uniform in time format. It can only be handled, and the three statements have been studied for an afternoon. I haven't used the CONVERT function and the case statement before, and " " operator will play different roles in different context environments, and I have dizzy, but it seems that it is almost a good. Turn all the values ​​such as "70.07.06" into "1970-07-06" Update LvshiSet Shengri = '19' Replace (ShenGri, '.', '-') where (zhiyezhenheng = '139770070153') in "1970" --07-06 "Extract" 70 "," 07 "," 06 "Select Substring (Shengri, 3, 2) As Year, Substring (Sinceri, 6, 2) AS Month, Substring (ShenGri, 9, 2) AS DayFrom lvshiwhere (zhiyezheng = '139770070153') converts a time type field into "1970-07-06" Update LvshiSet Shenling = Convert (VARCHAR (4), Year (Shenling)) '-' Case When Len (Month SHENLING) = 1 Then '0' Convert (Varchar (2), Month (Shenling)) Else Convert (Varchar (2), Month (Shenling)) End '-' Case When Len (Day (Shenling)) = 1 Then '0' Convert (CHAR (2), Day (Shenling)) Else Convert (VARCHAR (2), DAY (ShenLing)) endwhere (zhiyezheng = '139770070153')

转载请注明原文地址:https://www.9cbs.com/read-40376.html

New Post(0)