Conversion for various race

xiaoxiao2021-03-05  29

--- Layer Transformation Problem ----- Create Test Environment DROP TABLEA

Create Table Tablea (Name Varchar (50), A Varchar (50), B INT)

INSERT INTO TABLESET 'LICK', 'AN', 3 Union Allselect 'Lick', 'An', 3 Union AllSelect 'Lick3', 'AC', 4 Union AllSelect 'Lick4', 'An', 3 Union AllSelect 'Lick5' , 'An', 3 Union AllSelect 'Lick', 'Aan', 2 Union AllSelect 'Lick6', 'Ab', 5 Union AllSelect 'Lick7', 'DN', 3 Union AllSelect 'Lick8', 'An', 6Select * from TableAlick AN 3Lick AN 3LICK3 AC 4Lick4 An 3Lick5 AN 3Lick Aan 2lick6 AB 5Lick7 DN 3Lick8 AN 6

------------- Scene DECLARE @S nvarchar (4000) set @S = '' SELECT @ s @ S ',' a - It is best to change to Quotoname (a) or [ A] Form, otherwise it is possible to make an error '= ISNULL (RTRIM (Max (Case When A =' ---- max) can be changed to SUM Quotename (A, '' ') ' Ten B end)), ' '' ')' --- Isnull (a, '') function --- This is changed to you want, such as Isnull (A, '0')

From Tablea Group by Aexec ('SELECT NAME' @ S 'from Tablea Group By Name' - starting from Name, if there is a field in front, add it yourself ------------- - Result Name Aan AB AN DNLICK 2 3 LICK3 4 Lick4 3 Lick5 3 Lick6 5 Lick7 3Lick8 6

---- Delete Test Environment Drop Table TableAdrop Proc Colorow

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

New Post(0)