The input table looks like:
declare @mytable table
(
REG INT,
ISTR INT,
DAT DATETIME,
TRN INT
)
INSERT @mytable
SELECT 8, 1, '2023-04-23 00:00:00', 776862 UNION ALL
SELECT 03, 238, '2023-04-23 00:00:00', 300139 UNION ALL
SELECT 3, 238, '2023-04-23 00:00:00', 300139 UNION ALL
SELECT 12, 172, '2023-04-23 00:00:00', 237257 UNION ALL
SELECT 6, 1, '2023-04-23 00:00:00', 849848
SELECT * FROM @mytable
I am trying to generate 2 output table (one called as Original and other as Duplicate)
Rule:
Duplicate -->PadLeft(REG,'0',3) + PadLeft(ISTR,'0',5) + FormatDateTime(DAT, 'YYYYMMDDHHmmss' ) + PadLeft(TRN,'0',10)
Original --> Padleft 0 ,3 (REG (3 places) + STR (5 places) + DAT (14 places) + TRN (10 places)
The Output table contains data with below mention rule.
The Value For REG Should be always start from 3rd place, if not preceed with 0 to make it from Third Place.
The Value for ISTR always start from 5th Place, if not then preceed with 0 to make it at 5th place.
The Value for DAT always start from 14th Place, if not then preceed with 0 to make it at 14th place.
The Value for TRN always start from 10th Place, if not then preceed with 0 to make it at 10th place.
Can we do this with SQL?