I am new to SQL I hope this is an acceptable question.
I have a table with these relevant columns:
[ID] - this is the id of the data
[eventdescr] - a string containing the description of the value AND the value itself among other parameters eg. "L_OD_RESULT BR{0}DE{OD resultat}EU{AU}VA{0.72}SP{N/A}MN{N/A}MX{N/A}DC{3}EV{1}"
[unit] - the unit in which in which the value in [eventdescr] was measured
I need to create a new table with [ID] and a column for each relevant [eventdescr]-[unit] combination provided in a file with the following format:
250A, L[_]MIX[_]TIM[_]TOT BR PH[_]Z1APPL[_]FILL%
250B, L[_]MIX[_]TIM[_]TOT BR PH[_]Z1APPL[_]FILL%
250A, L[_]PRODUCT[_]VOL BR PH[_]Z1APPL[_]FILL%
250B, L[_]PRODUCT[_]VOL BR PH[_]Z1APPL[_]FILL%
252F, L[_]INAC[_]TM BR PH[_]Z2APPL[_]PHADJU%
252A, L[_]INAC[_]TM BR PH[_]Z2APPL[_]PHADJU%
I know how to select any specific combination:
SELECT TOP 1000 [ID]
,[eventdescr]
,[unit]
FROM [DB].[dbo].[eventview] where [eventdescr] like 'L[_]OD[_]RESULT BR%' and [unit] ='258A'
I have not however been able to figure out how to loop through the text file.
Basically, I want to do a for loop where the search terms are variables stored from the file provided.
for line in file:
myeventdescription=line[1]
myunit=line[0]
FROM [DB].[dbo].[eventview] where [eventdescr] like myeventdescription and [unit] =myunit
I apologise for the code above I know it is naive but I think it explains what I try to do.