if object_id('[tbtest]') is not null drop table [tbtest]
create table tbtest
(
A varchar(10) not null,
B varchar(50) not null
)
go
insert into tbtest
select 'A',1 union all
select'A',2 union all
select'A',3 union all
select'B',4 union all
select'B',5 union all
select'B',6 union all
select'B',7 union all
select'C',8 union all
select'C',9 union all
select'C',10 union all
select'C',11
go
if object_id('[dbo].[functiontest]') is not null drop function [dbo].[functiontest]
go
create function functiontest()
returns @tb table(A varchar(10),B varchar(50))
AS
begin
declare @a varchar(50)
declare @b varchar(50)
declare temp_cur cursor local for
select * from tbtest
open temp_cur
fetch next from temp_cur into @a,@b
while (@@fetch_status = 0)
begin
if(not exists(select * from @tb where A = @a))
insert into @tb(A,B)values(@a,@b)
else
update @tb set B = B + ',' + @b where A = @a
fetch next from temp_cur into @a,@b
end
return
end
go
select * from functiontest()
go
分享到:
相关推荐
详细描述了怎么重命名sqlserver表中字段名
SQL Server连接字段的方法 SQL Server连接字段的方法
查询某一表内同一字段内多个重复日期中最新的两个日期
此文档中详细的记载了,SQL Server分组排序取数据的实现,希望可以帮到下载的朋友们!
SQLServer中如何将一个字段的多个记录值合在一行显示
在sql server的字段中保存文件,文件大小没有限制。 字段类型2005以上是 varbinary(MAX),2000版本是image.
可以导出SQLSERVER表及字段说明.
该程序可将ORACLE中BLOB字段导入到SQL SERVER中的IMAGE字段,方便快捷。
SQL Server 2008 批量修改字段类型,查询出所有需要修改的字段,然后修改
本资料是一些SQLServer中常用字段类型
java读取sqlserver image字段.docx
从网上搜集的sqlserver自动增长字段设置方法
sqlserver实现Oracle中Lpad和Rpad函数
SQL SERVER字段类型说明SQL SERVER字段类型说明
C# 对SqlServer中Image字段的读写的思路是将图片转换为二进制在向数据库写.
一直在用ADOQuery读取数据库字段,当遇到SQL Server数据库Text型字段时,一直读取不全,在网上搜索很多遍未解决。试探将asstring 换为 CurValue。成功!
在SQLServer2000中实现存取照片字段
SQLServer判断表名和字段名
jsp与SQL Server 实现的图书管理系统,非常完美的资源,非常适合用于毕业设计
sqlserver字段类型介绍 数据库中,英文字符只需要一个字节存储就足够了,但汉字和其他众多非英文字符,则需要两个字节存储。如果英文与汉字同时存在,由于占用空间数不同,容易造成混乱,导致读取出来的字符串是乱码...