Combine two column in SQL

jn93 651 Reputation points
2022-12-01T07:41:43.31+00:00

Hi All,
Lets say I have two column like below. How can I combine two column to get the desired output like below. PACKAGENAME column in under varchar datatype whereas TRAN_DATE is under datetime datatype. The purpose I want to combine this two column is to get file name naming format as RL_TB_COMCN_TMI_yyyymmdd_hhmm for my SSIS package. Kindly please help.

   -- DDL and sample data population, start  
   DECLARE @tbl TABLE (PACKAGENAME varchar(200), TRAN_DATE DATETIME)  
   INSERT INTO @tbl (PACKAGENAME, TRAN_DATE) VALUES  
   ('RL_TB_COMCN_TMI','2022-08-01 20:10:30.000')  
     
   	SELECT *  
   FROM  @tbl   
    -- DDL and sample data population, end  

266051-image.png

SQL version:
266006-sql-version.png

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,451 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 40,741 Reputation points
    2022-12-01T07:45:28.287+00:00

    You can use the FORMAT function to convert the datetime into the wanted format:

    SELECT PACKAGENAME + FORMAT(TRAN_DATE, 'yyyyMMdd_HHmm')  
    FROM  @tbl  
    

0 additional answers

Sort by: Most helpful