I have a string pulling from XML. It is pulling a single value out of a record. the only part that changes when calling the item is the field name.
for example, the first below pulls the 'resolution' for the item, the second below pulls the 'name' of the item:
XMLData.value('(ImportFormXml/Resolution)[1]','VARCHAR(50)') AS Resolution
XMLData.value('(ImportFormXml/Name)[1]','VARCHAR(50)') AS Name
I would like to declare a variable and use it as one of the two ways below.
WAY 1 (Preferred)
DECLARE
@Var1 Varchar(50)
SET @Var1 = 'XMLData.value('(ImportFormXml/' [BE ABLE TO INSERT NAME HERE...THIS CAN'T BE ANOTHER VARIABLE]')[1]','VARCHAR(50)')
SELECT
@Var1 INSERT 'Resolution' AS Resolution
, @Var2 INSERT 'Name' AS Name
From TableX
WAY 2
DECLARE
@Var1 Varchar(50)
@Var2 Varchar(50)
SET @Var1 = 'XMLData.value('(ImportFormXml/'
SET @Var2 = ')[1]','VARCHAR(50)')
SELECT
@Var1 + 'Resolution' + @Var2 AS Resolution
, @Var1 + 'Name' + @Var2 AS Name
From TableX