sql - Group multiple result set by count -
I have a query that gives an edge to some data and returns the count if true, even though the number due to the loop Only counting that result, so you only return 1,1,1,1 etc .. Instead 4.
WHILE (@I & lt; = @RowCount) announcement announcement @forename VARCHAR (50) Announcement @surname VARCHAR (50) Select @DOB = #mytemp Previous Name Where = @I Selection @forename = #mytemp Previous Name Where Line = @I + 1 Select @surname = #mytemp from the previous name Select the line = @I + 2 COUNT (*) from [FPTDB] .dbo .clients where the former name = @forename and nickname = @surname and date of birth = @DOB set @I = @I + 3 end I think that to calculate the results Need to group a result, but I Not sure how.
I recommend leaving WHILE and you can do this (Last selection has not been tested): DECLARE @ mytemp TABLE (forename VARCHAR (100)) INSERT INTO @mytemp Select 'Tom' to enter @mytemp 'Bob' Select to enter @mytemp 'Smith' INSERT INTO @mytemp Choose Insert into 'Mary' @mytemp Select 'Tedy' Enter @mytemp 'Carry' INSERT INTO 'wmary' INSERT INTO Selection @mytemp Selection @ Mytemp 'wtedy' INSERT INTO 'wcarry' --ADD alias, former name and date of birth table Select Nbr in @mytemp (column isType); SELECT forename, CASE when id = 3 = 0 THEN 3 - Name when ID% 3 = 2 THEN 2 - First name (as SELECT forename, ROW_NUMBER () as mytemp) ELSE 1 - Date of birth as isType by mytemp command # on myTemp2 ID check based on ID / * This former name id isType Bob 1 1 Carry 2 2 Mary 3 3 Smith 4 1 Tedy 5 2 Tom 6 3 Wcarry 7 1 wmary 8 2 wtedy 9 3 results like * / - Just select the table 3 times (*) from FROM [FPTDB] * T1 as dbo.clients T1 on DOB as C Inner # myTemp2. Join FNname = CDob and T1.isType = 1 INNER # myTemp2 T2 as T2.forename = C.forename --forename and T2.isType = 2 Internal # myTemp2 as soon as it is included T3.forename = C on T3 .surname --surname and T3.isType = 3
Comments
Post a Comment