將一條記錄中的字段拆成多條記錄

 
  --刪除測試  
  drop   table  #t

  --分拆處理  
  declare @i int  
  select @i=max(len(tpno)) from tr_job  
  set rowcount @i  
  select id=identity(int) into #t from syscolumns a,syscolumns b  
  set rowcount 0  
   
  select a.jobno
  ,tpno=substring(a.tpno,b.id,charindex(',',a.tpno+',',b.id)-b.id)  
  from tr_job a,#t b  
  where b.id<=len(a.tpno) and substring(','+a.tpno,b.id,1)=','  

發佈了24 篇原創文章 · 獲贊 0 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章