I have the following XQuery code:;WITH XMLNAMESPACES('SIMATIC_BATCH_V7_0_1' AS y)SELECT a.value('@timestamp', 'datetimeoffset(0)') AS Date, a.value('@state', 'nvarchar(20)') AS State, a.value('@exstate', 'int') AS ExState FROM #ModifTable AS TCROSS APPLY XmlData.nodes('/y:Archivebatch/y:Cr/y:Crdatacltn/y:Crdata') AS x(a)WHERE T.ID = 132which produces:Date State ExState2010-04-22 09:37:09 +00:00 2 02010-04-22 09:37:17 +00:00 4 02010-04-22 09:37:17 +00:00 5 02010-04-22 09:37:33 +00:00 7 02010-04-22 09:37:34 +00:00 8 02010-04-22 09:40:10 +00:00 8 1282010-04-22 09:40:23 +00:00 8 02010-04-22 09:40:33 +00:00 8 1282010-04-22 09:40:43 +00:00 8 02010-04-22 09:42:18 +00:00 8 128
Now, what I would like to do have another column called "Description" which, depending on the values of State and ExState displays a description of the state. For example: State=8 AND ExState=0 displays "Running"State=8 AND ExState=128 displays "Running + Subelement Active"My initial idea was to assign the result of: a.value('@state', 'nvarchar(20)') to a local variable "@XMLState" like:SELECT a.value('@timestamp', 'datetimeoffset(0)') AS Date, @XMLSate = a.value('@state', 'nvarchar(20)'), a.value('@exstate', 'int') AS ExStateThis does not work. I get the error:A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.Firstly, is there a way of assigning the value of an XQuery result to a local variable? Is my syntax incorrect?Or is there a way of displaying different values to a local variable @Description depending on the results from the XQueries above?