Share via

updare dateid in table

RUPESH SHELAR 0 Reputation points
2024-07-10T18:59:02.5066667+00:00

HI,

Hw to update date datatype into integer column to varchar column

create table table1(dateid date,dateid1 int,dateid2 varchar(23) )

dateid --------------------- dateid1 -------------dateid2

2024-01-01 ------------------20240101---------------- 2024 Jan 01

SQL Server Integration Services
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other

2 answers

Sort by: Most helpful
  1. LiHongMSFT-4306 31,621 Reputation points
    2024-07-11T01:45:09.26+00:00

    Hi @RUPESH SHELAR

    Try this:

    UPDATE table1
    SET dateid1 = CAST(CONVERT(varchar(8),dateid,112) as int),
        dateid2 = CONCAT_WS(' ',YEAR(dateid),convert(varchar(6),dateid,107))
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.
    0 comments No comments

  2. Erland Sommarskog 133.6K Reputation points MVP Volunteer Moderator
    2024-07-10T20:03:53.8833333+00:00

    Two ways, one working on the date column and one on the id column.

    SELECT concat_ws(' ', date1%10000, left(datename(month, convert(date, convert(char(8), dateid1))), 3), right(convert(char(8), dateid1), 2))
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.