执行联接后从SQL Server中的XML中提取信息

时间:2019-01-28 15:02:10

标签: sql sql-server xml tsql

我有一个通过以下代码创建的SQL表,其中的列UserDefinedXML包含我需要提取的信息。

>>> re.split(r'\W*', '...words...')
['', '', 'w', 'o', 'r', 'd', 's', '', '']

>>> re.split(r'(\W*)', '...words...') ['', '...', '', '', 'w', '', 'o', '', 'r', '', 'd', '', 's', '...', '', '', '']

enter image description here

我已经通过R中的许多gsubs提取了它,但是效率很低,而且不是实现它的最佳方法,我敢肯定。 XML格式如下

SELECT A.ExternalID, A.UserDefinedXML, A.ServiceSiteUid, A.LastModifiedDate, A.PersonUid,
       B.FirstName, B.LastName, B.PersonUid,
       C.Name
  FROM Patient A
  INNER JOIN Person B ON B.PersonUid = A.PersonUid
  INNER JOIN ListServiceSite C ON C.ServiceSiteUid = A.ServiceSiteUid
  WHERE A.UserDefinedXML IS NOT NULL
  ORDER By LastModifiedDate

目前,我只是对在<data> <LOA> <NotMedNecessaryInsCompany ControlType="PrmTextBox" Value="" Label="" /> <DicontinuedDate ControlType="FindDateBox" Value="" Label="" Display="false" /> <ReceivedDate ControlType="FindDateBox" Value="" Label="" Display="false" /> <SentDate ControlType="FindDateBox" Value="" Label="" Display="false" /> <ReasonDiscontinued ControlType="PrmTextBox" Value="" Label="" /> <NoOONBenefitsInsCompany ControlType="PrmTextBox" Value="" Label="" /> <InsuranceStatus ControlType="PrmGroupBox" Label="" Value="" /> <OtherReasonDenied ControlType="PrmTextBox" Value="" Label="" /> <FacilityRefused ControlType="PrmCheckBox" Value="false" Label="Facility Refused" /> <ReasonDenied ControlType="PrmCheckBox" Value="false" Label="Other" /> </LOA> <Forms> <POReceivedDate ControlType="FindDateBox" Value="" Label="" Display="false" /> <InformedConsentReceivedDate ControlType="FindDateBox" Value="" Label="" Display="false" /> <AuthorizationToTreatReceivedDate ControlType="FindDateBox" Value="" Label="" Display="false" /> </Forms> <Skin_Sheet> <SkinSheet ControlType="PrmGroupBox" Label="No" Checked="PrmRadioButton1" Value="" /> </Skin_Sheet> </data> 标头下的最后几行中选择“是”还是“否”感兴趣。最终,我将需要能够访问此字符串中的所有字段。不幸的是,我对SQL非常缺乏经验,并且在工作中被投入使用,因此我想即时学习。

1 个答案:

答案 0 :(得分:1)

假设def AjaxClockJobCreate(request, user_id): form = JobFormInClock(request.POST, instance=User.objects.get(id=user_id)) user = get_object_or_404(User, pk=user_id) if request.method == "POST" and request.is_ajax() and form.is_valid(): instance = Jobs( job_company = request.user.userprofile.user_company, job_group = form.cleaned_data['job_group'], job_name = form.cleaned_data['job_name'], job_number = form.cleaned_data['job_number'], job_description = form.cleaned_data['job_description'], job_start_date = datetime.datetime.now(), job_start_time = datetime.datetime.now(), job_end_date = datetime.datetime.now() + datetime.timedelta(days=1), job_end_time = datetime.datetime.now() + datetime.timedelta(hours=15), job_created_by = request.user, job_updated_by = request.user, job_status = 'Active' ) instance.save() instance.job_users.add(user) lastest_entry = Jobs.objects.latest('id') data = { 'job_value': lastest_entry.id, 'job_name': lastest_entry.job_name, 'error_message': 'Could not enter job.' } return JsonResponse(data) 是XML数据类型,只需使用value函数:

UserDefinedXML