Forum Discussion
SQLDBA201400
Feb 20, 2025Copper Contributor
Query Help to show record in single row
Hi All, need help with an SQL query. Currently we are getting Start and End BNames on separate rows. DECLARE @tblData TABLE
(BName varchar(50),
StartDate varchar(10),
StartTime varch...
SivertSolem
Feb 21, 2025Iron Contributor
Your insert statements confound me.
Do you have a table that's already formatted that way, and you're having trouble extracting the data the way you want it, or are you struggling with inserting and updating rows to your table?
Changing your "End" inserts to updates will at least leave the table in the format you requested.
DECLARE @tblData TABLE
(BName varchar(50),
StartDate varchar(10),
StartTime varchar(10),
EndDate varchar(10),
EndTime varchar(10))
INSERT INTO @tblData (BName, StartDate, StartTime) VALUES ('STAT','02/20/2025','00:34:02')
UPDATE @tblData set EndDate = '02/20/2025', EndTime= '00:40:36' where BName = 'STAT'
INSERT INTO @tblData (BName, StartDate, StartTime) VALUES ('CDS','02/20/2025','00:40:38')
UPDATE @tblData set EndDate = '02/20/2025', EndTime = '00:47:26' where BName = 'CDS'
INSERT INTO @tblData (BName, StartDate, StartTime) VALUES ('LED','02/20/2025','00:40:42')
UPDATE @tblData set EndDate = '02/20/2025', EndTime = '00:54:28' where BName = 'LED'
Select * from @tblData
SQLDBA201400
Feb 21, 2025Copper Contributor
Sorry I was not clear in my ask. I have a table that's already formatted that way, and I am having trouble extracting the data the way I want it.