- Vertical behavior

xiaoxiao2021-03-06  118

- Vertical Table - Create Table Create Table A (IN VARCHAR (20), Date SmallDateTime, Time VARCHAR (20)) - Insert Test Data Insert Ite Select '01', '2004-10-01 ', '07: 50'Union Select' 01 ',' 2004-10-01 ', '11: 35'Union SELECT' 01 ',' 2004-10-01 ', '14: 20'Union Select' 01 ' , '2004-10-02', '08: 01'Union Select '01', '2004-10-02', '14: 30'Union Select '02', '2004-10-01', '07: 55'Union select '02', '2004-10-02', '07: 58'Union select '03', '2004-10-01', '07: 56 '- Create a stored procedure create proc p_tasdeclare @ID VARCHAR (20), @ Date SmallDatetime, @ Time Varchar (50) Select * Into #a from a ORDER BY INTS, Date, Time Update #a set time = Case WHEN (Date = @ ID) and (Date = @ @ @ i) Date) THEN @Time Else Time End, @ Time = Case WHEN (Date = @ Date) Then @time ',' Time ELSE Time End, @ ID = IM, @ Date = Date SELECT work number, date, max (time) AS time from #a group by work number, date ORDER BY card number - execution EXEC P_T - Test results Time Date Date ------------ --------------------------------- 01 2004-10-01 00:00:00 07: 50, 11: 35,14: 2001 2004-10-02 00:00:00 08: 01, 14: 3002 2004-10-01 00:00:00 07: 5502 2004-10-02 00:00:00 07: 5803 2004- 10-01 00:00:00 07:56 (5 lines affected by 5 lines) Elect [Empid] from [EMPLOYEE]

I want to merge it into this result: Zhang San, Li Si, Wang Wu ..., ...

Declare @s varchar (8000) set @S = '' SELECT @ s = @ s ',' [Empid] from [Employee] Print stuff (@ s, 1, 1, ') Declare @sql varchar (2000) Set @SQL = '' SELECT @ SQL = @ SQL [Empid] ',' from [Employee] set @ SQL = Left (@ SQL, LEN (@SQL) -1) Print @SQL

转载请注明原文地址:https://www.9cbs.com/read-99522.html

New Post(0)