create function get_strarraylength
( @str varchar(1024), --要分割的字串
@split varchar(10) --分隔符號
) returns int
as begin
declare @location int
declare @start int
declare @length int
set @str=ltrim(rtrim(@str))
set @location=charindex(@split,@str)
set @length=1
while @location<>0
begin
set @start=@location+1
set @location=charindex(@split,@str,@start)
set @length=@length+1
end
return @length
end
gocreate function get_strarraystrofindex
( @str varchar(1024), --要分割的字串
@split varchar(10), --分隔符號
@index int --取第幾個元素
) returns varchar(1024)
as begin
declare @location int
declare @start int
declare @next int
declare @seed int
set @str=ltrim(rtrim(@str))
set @start=1
set @next=1
set @seed=len(@split)
set @location=charindex(@split,@str)
while @location<>0 and @index>@next
begin
set @start=@location+@seed
set @location=charindex(@split,@str,@start)
set @next=@next+1
end
if @location =0 select @location =len(@str)+1
return substring(@str,@start,@location-@start)
end
go create procedure insertuservaluepro
@valueids nvarchar(100) ,
@userid nvarchar(50)
asbegin
declare @next int
set @next=1
declare @count int
declare @valid nvarchar(20)
while @next<=dbo.get_strarraylength(@valueids,',')
begin
set @valid = dbo.get_strarraystrofindex(@valueids,',',@next)
--print @valid
select @count=count(userid) from t_uservalue where userid=@userid and valueid = @valid
print @count
if(@valid ='' or @valid is null )
begin
delete from t_uservalue where userid=@userid
endelse if(@count <= 0)
begin
insert into t_uservalue values(@userid,@valid)
endelse if(@count > 0)
begin
delete from t_uservalue where userid=@userid
insert into t_uservalue values(@userid,@valid)
endset @next=@next+1
end
endgo
--exec insertuservaluepro '','49'
--select * from dbo.t_uservalue where userid=49
insert into插入多行資料
如何用insert into語句插入多行資料?這是今天一朋友的問題,解決辦法如下 只限於ms sql和my sql資料庫中,其它資料庫沒有測試 下面以例項來說明這個問題 建立乙個使用者表,包括姓名和年齡 create table tablename name varchar 20 primary k...
Pandas插入多行資料
1.匯入資料 import pandas as pd music pd.read csv music.csv music 內容如下 2.建立新的dataframe,包含要新增的row,並且令列名等於原表 music 的列名,這裡新增兩個人,乙個60歲,乙個61歲 new rows pd.datafr...
插入多行資料的方法
1.最原始的方法,一條一條的插入 insert into student values 95001,李勇 男 20 cs insert into student values 95002,劉晨 女 19 is 2.insert into student select 95001,李勇 男 20 cs...