sql - concatenating calculations from different table columns into a string -
I asked a similar question for this and then the answer was needed, this question is slightly different because one of the columns Is from a different table. Here are tables and values:
Dish table
Name Cook timings yield service Anchor Stroganoff 150 10 3 Lasagna 180 24 3 Chicken Carbonate 175 13 Chicken Fettussen 15 3 6 Chilean Cheeseburger 10 Dish 2 table
Name TestIntCol Stroganoff 12 Lasagna 12 Chicken Carbonate 12 Chicken Fettucine 12 Chilli Cheeseburger 12 Chicken Fettucine 12
What I want to achieve is this:
Name Laser Chicken Carbonate 0.00 Chicken Fettuchen 2.00,0.00 Chile Cheeseburger 12.00 Lasagna 4.00 Str Guyof 4.00
Although what I'm getting is:
Name Laser Chicken Carbona 0.00,2.00,4.00,12.00 Chicken Fake Tucine 0.00.2.00,4.00 , 12.00 Chile Cheeseburger 0.00,2.00,4.00,12.00 Lasagna 0.00.2.00.4.00,12.00 Stroganoff 0.00.2.00.4.00,12.00
My code is here:
Select I.Name, if you divide by zero, set it to zero and then set the zero value to zero. (Substring) in the form of 'Varkar (maximum)) in DISC 2L in Dist Kashmir' as Cast (Elastist call / Niuliffe (KSV) lift as' decimal (10, 2)), 0) , 0)). On the calculation of the expression L. Name = KName - on the group where L. Name = KName group is given by ISNULL (cast (L. testinentol / nuulif (k.v. vording lift, 0) as decimal (10, 2)), 0) XML path ('')), 2, 1000) as a laser from dish to I.Name = I.Name at I.Name = J.Name group in Dish 2J.
I have read that the grouping should help with the outcome of the expression but it is not. I've been stuck on this for a few days I have looked around but the correct answer for my scenario is not found Thank you for the help.
You can use CTE to simplify things:
; With CTE (Selection I.Name, ISNULL (CAST (Zeststynol / Nullif (IS Serving Lift, 0) DCIML (10, 2)), 0) AS TempLaser FROM Dish I INNER Dish2 J ON I.Name = J .Name) Select c. Name, STFF ((SELECT ',' + + CAST ([TempLaser] AS VARCHAR (MAX)) CTE from where (name = c. Name) for XML path ('')), 1, 2, '' Type C by the CSE C group in laser form to create the required result set, OP DISTINCT inside CTE (Chicken Fettucin 12) had been repeated twice in sample data given in OP.
Comments
Post a Comment