日期:2014-05-18 浏览次数:21040 次
create table BookLoan (ID int primary key identity(1,1), BookName varchar(200), DateLoan datetime, CardNo varchar(200), ) insert into BookLoan(BookName , DateLoan , CardNo ) values('1电脑管理与维护','2010-3-25','2001') insert into BookLoan(BookName , DateLoan , CardNo ) values('2藏地密码','2010-3-25','2001') insert into BookLoan(BookName , DateLoan , CardNo ) values('3档案信息检索','2010-3-25','2001') insert into BookLoan(BookName , DateLoan , CardNo ) values('4射雕英雄传','2010-3-25','2002') insert into BookLoan(BookName , DateLoan , CardNo ) values('5C#编程','2010-4-24','2002')
create table BookLoan (ID int primary key identity(1,1), BookName varchar(200), DateLoan datetime, CardNo varchar(200), ) insert into BookLoan(BookName , DateLoan , CardNo ) values('1电脑管理与维护','2010-3-25','2001') insert into BookLoan(BookName , DateLoan , CardNo ) values('2藏地密码','2010-3-25','2001') insert into BookLoan(BookName , DateLoan , CardNo ) values('3档案信息检索','2010-3-25','2001') insert into BookLoan(BookName , DateLoan , CardNo ) values('4射雕英雄传','2010-3-25','2002') insert into BookLoan(BookName , DateLoan , CardNo ) values('5C#编程','2010-4-24','2002') if object_id('getnum') is not null drop function getnum create function getnum(@DateLoan varchar(50),@CardNo varchar(50)) returns varchar(50) as begin declare @sql varchar(50) set @sql='' select @sql=@sql+BookName+',' from BookLoan where DateLoan=@DateLoan AND CardNo=@CardNo set @sql=@sql return @sql end SELECT DISTINCT LEFT(dbo.getnum(DateLoan,CardNo),LEN(dbo.getnum(DateLoan,CardNo))-1) AS BookName,DateLoan,CardNo FROM BookLoan GROUP BY DateLoan,CardNo,BookName /* BookName DateLoan CardNo -------------------------------------------------- ----------------------- ---------------- 1电脑管理与维护,2藏地密码,3档案信息检索 2010-03-25 00:00:00.000 2001 4射雕英雄传 2010-03-25 00:00:00.000 2002 5C#编程 2010-04-24 00:00:00.000 2002 (3 行受影响) */
------解决方案--------------------