当前位置: 代码迷 >> Sql Server >> 存储怎么向原来字段中追加数据
  详细解决方案

存储怎么向原来字段中追加数据

热度:208   发布时间:2016-04-27 19:28:32.0
存储如何向原来字段中追加数据
存储如何向原来字段中追加数据 
原来有u_friends字段,内容为uid1,uid2, 
现在传入一个数据为uid3, 
所以后来更新为uid1,uid2,uid3, 

如果不用存储,在程序中肯定是先读出uid1,uid2, 
后把uid1,uid2,uid3,更新到数据中。 

我现在想用存储来完成。 
我基本没看过存储 
自己按自己想法写了一个没用。因为我对存储没有基本知识。 

CREATE PROCEDURE addfriends 

@fid nvarchar(50), 
@uid nvarchar(50), 
@oldfids nvarchar(3000) output 

AS 
select @oldfids=[u_friends] from [ac_user] where [u_id][email protected] 
update [ac_user] set [u_friends] [email protected][email protected] where [u_id][email protected] 
GO



------解决方案--------------------

update T
set [email protected]
------解决方案--------------------
SQL code
改下:CREATE PROCEDURE addfriends  (  @fid nvarchar(50),  @uid nvarchar(50)  )  AS  update [ac_user] set [u_friends] = [u_friends] + ',' + @fid where [u_id][email protected]  GO
  相关解决方案