sql如何將欄位拆分成單個字元如圖

2022-03-03 05:06:25 字數 3877 閱讀 5106

1樓:匿名使用者

可以用substring函式來處理:

select substring(styleid,1,1) as styleid_1,substring(styleid,2,1) as styleid_2,substring(styleid,3,1) as styleid_3,substring(styleid,4,1) as styleid_4,substring(styleid,5,1) as styleid_5 from 表

2樓:山水阿銳

您好,您可以參考下面的程式:

declare @str varchar(20)set @str = 'abcdefg'

declare @i int

declare @count int

select @count = 0

select @i = len(@str)declare @str1 varchar(20)select @str1 = ''

while (@i > @count)

begin

select @count = @count + 1select @str1 = @str1 + substring (@str,@count,1) + '.'

endprint @str1

這個字串,你可以從表欄位中獲取,也或者可以直接賦值,最好@str1就是你想要的輸出。

3樓:鏡湖之人

你度娘看下字串的擷取函式應該就知道了。

sql資料庫 根據一個欄位的值 拆分成兩個欄位

4樓:匿名使用者

省和市之間是有 空格分隔的對嗎?

如果是的話 你可以擷取啊

先判斷空格的位置 position(' 'in column_name)

再擷取字串就可以了

substr(column_name,1,position('' in column_name)) --省

substr(column_name,position('' in column_name)+1) --市

5樓:

update 表

set province=case when instr(attribution,' ')=0 then attribution else substr(attribution,0,instr(attribution,' ')-1) end,

city=case when instr(attribution,' ')=0 then attribution else substr(attribution,instr(attribution,' ')+1) end

sql 把一個欄位分成多個欄位

6樓:小丁創業

方法和詳細的操作步驟如下:

1、第一步,新的php檔案,見下圖,轉到下面的步驟。

2、第二步,執行完上面的操作之後,需要宣告陣列變數,見下圖,轉到下面的步驟。

3、第三步,執行完上面的操作之後,使用函式將陣列連線到帶有連線字元的字串,見下圖,轉到下面的步驟。

4、第四步,執行完上面的操作之後,輸出連線的字串,見下圖,轉到下面的步驟。

5、第五步,執行完上面的操作之後,預覽的效果見下圖,轉到下面的步驟。

6、第六步,執行完上面的操作之後,使用「implode」函式將陣列拼接成字串,使用「?」進行連線,見下圖。這樣,就解決了這個問題了。

7樓:千鋒教育

舉例:原始sql:

select

province_code,

city_code,

zone_code

from civ_p_cust

原始結果:

拆分sql:

select

substring(province_code,1,patindex('%〓%',province_code)-1) as pid,

substring(province_code,patindex('%〓%',province_code)+1,len(province_code)) as pname,

substring(city_code,1,patindex('%〓%',city_code)-1) as cid,

substring(city_code,patindex('%〓%',city_code)+1,len(city_code)) as cname,

substring(zone_code,1,patindex('%〓%',zone_code)-1) as zid,

substring(zone_code,patindex('%〓%',zone_code)+1,len(zone_code)) as zname

from civ_p_cust

拆分結果:

8樓:匿名使用者

我的思路是:

1、先判斷b列中的最多的「-」,建表,同時將資料插入到新表;

2、用charindex判斷後,每列去更新。

9樓:匿名使用者

select a, dbo.split(b,'-',1) as b1, dbo.split(b,'-',2) as b2, dbo.

split(b,'-',3) as b3, c from t_fengchujun

在執行上面的語句前,需要先建立一個字串函式**如下,在查詢分析器執行

create function dbo.split(

@srcstr varchar(4000),

@space varchar(50),

@showindex int

)returns varchar(4000)

begin

declare @pos1 int

declare @pos2 int

declare @index int

declare @return varchar(4000)

set @pos1 = 0

set @pos2 = 0

set @index = 0

set @srcstr = @srcstr + @space

while @index<@showindex

begin

set @pos1 = @pos2

set @pos2 = charindex(@space,@srcstr,@pos1+1)

if @pos2-@pos1-1>0

set @return = substring(@srcstr,@pos1+1,@pos2-@pos1-1)

else

begin

set @pos2 = len(@srcstr)

set @return = ''

endset @index = @index + 1

endreturn(@return)

endgo

10樓:匿名使用者

這個只用sql語句比較麻煩,由於不確定性存在,基本不可能完善解決,最好辦法是結合程式來做

11樓:

sql只是資料儲存語言,本身對程式處理並不是很強

和樓上所說一樣,最好在前臺處理

sqlserver中怎麼將一列資料拼接成一個字串,並以換行符分開

12樓:匿名使用者

select w, x = (stuff((select ',' + x from table where w = a.w for xml path('')),1,1,'')) from table a group by w

-- 將w相同的x列拼接成一個字串用逗號隔開

怎麼拆分pdf檔案?如何把PDF拆分成單頁檔案

1 首先找到我們要拆分的檔案點選右鍵 使用迅捷編輯器開啟 2 開啟檔案後點選頂部欄目 文件 彈出選單選擇 拆分文件 3 選擇拆分頁數和存放位置後點選 確定 就可以拆分了。4 拆分結果如下。請你安裝adobe acrobat xi pro軟體,開啟你的pdf檔案,在工具 頁面 提取,選擇你要提取的起止...

sql中如何將相同欄位的其它欄位拼接在一起放到另欄位裡面

sql中如何將相同欄位 的其它欄位拼接在一起放到另一個欄位裡面的方法。如下參考 1.將新表select 的表結構和資料程度從源表名複製到目標表名中 需要不存在目標表,因為在插入查詢時將自動建立它 如下圖。2.僅將表結構複製到新表createtable新表select from舊錶where1 2 3...

excel如何拆分行,excel 如何將一個單元格拆分成多行或多列?

是111 換行 222 換行 333嗎?替換 按著alt按小鍵盤1和0,相當於換行符號 為 一個空格 然後調整單元格寬度為3個字元,僅能看到111然後編輯 填充 內容重排 你自己拖動列交際線就可以調整列寬度了。單元格內的資料想要拆分開,試試ctrl e鍵吧!你是指把已經合併的單元拆分成沒有合併前嗎?...