How could I achieve something like this??
DECLARE @TEMP_TABLE TABLE (DATA VARCHAR(MAX), SHADOW_ID INT)
DECLARE @TEMP_TABLE1 TABLE (ENT VARCHAR(MAX), RMR VARCHAR(MAX), DTM VARCHAR(MAX))
INSERT INTO @TEMP_TABLE1 (ENT) SELECT DATA from @TEMP_TABLE WHERE DATA LIKE 'ENT%'
INSERT INTO @TEMP_TABLE1 (RMR) SELECT DATA from @TEMP_TABLE WHERE DATA LIKE 'RMR%'
INSERT INTO @TEMP_TABLE1 (DTM) SELECT DATA from @TEMP_TABLE WHERE DATA LIKE 'DTM%'
without having any null values, because each statement populates 1 column and nulls into the other two.
Thanks!
It looks like you’re trying to create a pivot or cross-tab query.
This is assuming that you have only one ENT, RMR and DTM value for each SHADOW_ID. If this is not the case, then I must agree with @JeremyHolovacs.
I would recommend putting SHADOW_ID into @TEMP_TABLE1 as well, so you could know where the data came from.