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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,977 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,590 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,652 questions
{count} votes

2 answers

Sort by: Most helpful
  1. LiHongMSFT-4306 27,961 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 112.7K Reputation points MVP
    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 Answers by the question author, which helps users to know the answer solved the author's problem.