从“自己的”子查询列插入#temp表

时间:2019-11-15 08:40:46

标签: sql split subquery insert-update sql-server-2017

我的目标是将值从STRING_SPLIT列获取到临时表中。到目前为止,我设法将值分成这样的表,很好: Result from insert and select

问题是value列只是'temp'选择的值,不包含在INSERT中。我需要其中两个表,并需要进行联接,因此为了简化-我需要将值插入相同的INSERT和子查询SELECT中。我一直在寻找SO,但是找不到类似的情况。我希望INSERT INTO需要更新,但不确定如何进行更新。任何指向正确方向的指示都会有所帮助。

这是我目前正在测试的代码:

set @inputURL = 'https://sim-ser.blab.kotabl.co/insert_user_in_stored_procedure.asp?hf_autentisatorID=abcd&hf_autentisator_ansvar=150&fld_Username=Pela&fld_Username_m=&fld_Username_e=Boing&fld_Mobilephone=90153150&fld_Workphone=72912121&fle_email=peb.saakolen%40sarvok.kimmone.co&fld_Employee_sn=121181&fld_userident=BESA&fld_hrmID=BESA&hf_klassifisering=Avdelingsleder+(offentlig+administrasjon&hf_ansettelse=Fast+ansatt&hf_workTitle=Enhetsleder&hf_orgID=150&chLukket=on&hf_hprNR=&hf_helseprofession=&tblKompetanse_length=10&hf_pnr=13039026863&fld_start_dato=&fld_slutt_dato=&inst=4&avd=&avd=5&avd=20&avd=23&avd=24&hf_insID=4&hf_avdID=3%2C5%2C20%2C23%2C24&sel_distrikt=5&sel_sone=21&sel_sone=22&sel_sone=23&hf_disID=5&hf_soID=21%2C22%2C23&sel_applikasjon1=42&sel_tilgang1=165&sel_tilgang1=226&sel_tilgang1=225&fld_stillingID=1&fld_ansvar=150&fld_tjeneste=12014&fld_sted=&fld_kommentar=%3E12.11.2019+%3Apaqa%0D%0ADette+er+en+test&chDebug=false'
set @URL = REPLACE(@inputURL, '&', ';');

SELECT @URL = (SUBSTRING(@URL,CHARINDEX('?',@URL,0)+1,LEN(@URL)))

  CREATE TABLE #app_list (
  Id int NOT NULL IDENTITY(1, 1),
  appname VARCHAR(MAX)/*,
  appId int*/
  )

INSERT INTO #app_list
  SELECT * FROM STRING_SPLIT(@URL, ';') where value like '%sel_applikasjon%'
  (SELECT * FROM #app_list AL
   CROSS APPLY STRING_SPLIT(appname, '=') AS AN
   where value NOT LIKE '%sel_applikasjon%'
   )    

SELECT * FROM #app_list /* Want to have value properly inserted as well */

DROP table #app_list

0 个答案:

没有答案