第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

sqlServer 2008 一行轉(zhuǎn)多行的問題怎么解決呢?

sqlServer 2008 一行轉(zhuǎn)多行的問題怎么解決呢?

米脂 2018-12-07 00:13:20
現(xiàn)有如下一張表 id????? txt 1  ed 2  aa,dd 3  xx,yy,asdfg 4  dfgf,dfkgjj 5  ax,fg,aaaaaaa,dfkgjj 要求變成 id????? txt 1  ed 2  aa 2  dd 3  xx 3  yy 3  asdfg 4  dfgf 4  dfkgjj 5  ax 5  fg 5  aaaaaaa 5  dfkgjj ? 我現(xiàn)在解決是解決了? 但是很笨的方法 求解 稍后附上自己代碼 謝謝!
查看完整描述

7 回答

?
瀟湘沐

TA貢獻1816條經(jīng)驗 獲得超6個贊

pivot

查看完整回答
反對 回復 2019-01-07
?
HUH函數(shù)

TA貢獻1836條經(jīng)驗 獲得超4個贊

你的結(jié)果跟我的問題 不太相符 不過還是謝謝了

查看完整回答
反對 回復 2019-01-07
?
郎朗坤

TA貢獻1921條經(jīng)驗 獲得超9個贊

 1 select * from Table_1;
 2 create table #table_temp(
 3 id int identity(1,1) not null,
 4 txt varchar(50));
 5 declare mycur cursor for select txt from Table_1
 6 open mycur
 7 declare @t_txt varchar(50),@t_txt1 varchar(50)
 8 fetch next from mycur into @t_txt
 9 while(@@FETCH_STATUS = 0)
10 begin 
11 if CHARINDEX(',',@t_txt)> 0
12 begin
13   while(CHARINDEX(',',@t_txt)> 0 )
14   begin
15   set @t_txt1 = substring(@t_txt,1,CHARINDEX(',',@t_txt)-1)
16   insert #table_temp(txt) values(@t_txt1)
17   set @t_txt = SUBSTRING(@t_txt,CHARINDEX(',',@t_txt)+1,LEN(@t_txt) - LEN(@t_txt1))
18   end
19   insert into #table_temp(txt) values (@t_txt)
20 end
21 else
22 begin
23 insert #table_temp(txt) values(@t_txt)
24 end
25 fetch next from mycur into @t_txt
26 end
27 close mycur
28 deallocate mycur
29 select * from #table_temp
30 drop table  #table_temp

?

@yj_smile:?create table #table_temp(
id int identity(1,1) not null,
txt varchar(50));
declare mycur cursor for select txt from Table_1
open mycur
declare @t_txt varchar(50),@t_txt1 varchar(50)
fetch next from mycur into @t_txt
while(@@FETCH_STATUS = 0)
begin
if CHARINDEX(',',@t_txt)> 0
begin
? while(CHARINDEX(',',@t_txt)> 0 )
? begin
? set @t_txt1 = substring(@t_txt,1,CHARINDEX(',',@t_txt)-1)
? insert #table_temp(txt) values(@t_txt1)
? set @t_txt = SUBSTRING(@t_txt,CHARINDEX(',',@t_txt)+1,LEN(@t_txt) - LEN(@t_txt1))
? end
? insert into #table_temp(txt) values (@t_txt)
end
else
begin
insert #table_temp(txt) values(@t_txt)
end
fetch next from mycur into @t_txt
end
close mycur
deallocate mycur
select * from #table_temp
drop table? #table_temp

不知道怎么提交代碼?。。?!

以上是用游標實現(xiàn)的

查看完整回答
反對 回復 2019-01-07
?
人到中年有點甜

TA貢獻1895條經(jīng)驗 獲得超7個贊

@MaxGeek:?游標效率太低的 在文章結(jié)尾,我已經(jīng)給出了最佳解決方案 ,請知悉

查看完整回答
反對 回復 2019-01-07
?
BIG陽

TA貢獻1859條經(jīng)驗 獲得超6個贊

create table #table_temp( id int identity(1,1) not null, txt varchar(50)); declare mycur cursor for select txt from Table_1 open mycur declare @t_txt varchar(50),@t_txt1 varchar(50) fetch next from mycur into @t_txt while(@@FETCH_STATUS = 0) begin if CHARINDEX(',',@t_txt)> 0 begin while(CHARINDEX(',',@t_txt)> 0 ) begin set @t_txt1 = substring(@t_txt,1,CHARINDEX(',',@t_txt)-1) insert #table_temp(txt) values(@t_txt1) set @t_txt = SUBSTRING(@t_txt,CHARINDEX(',',@t_txt)+1,LEN(@t_txt) - LEN(@t_txt1)) end insert into #table_temp(txt) values (@t_txt) end else begin insert #table_temp(txt) values(@t_txt) end fetch next from mycur into @t_txt end close mycur deallocate mycur select * from #table_temp drop table #table_temp

查看完整回答
反對 回復 2019-01-07
  • 7 回答
  • 0 關注
  • 1318 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號