clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 648404 fiddles created (15128 in the last week).

Create Table #Orders ( id int IDENTITY(1,1) PRIMARY KEY NOT NULL ,partid varchar(100) NOT NULL ,qtyordered int DEFAULT '0' ,dividedBy int DEFAULT 1 ,orderedby varchar(100) NOT NULL ,ordereddate date DEFAULT GETDATE() ) ; Insert Into #Orders (partid, qtyordered, dividedBy, orderedby) VALUES ('SS100', 10, 3, 'James'), ('RR200', 15, 6, 'Bob'), ('NN300', 3, 2, 'Jake'), ('OO400', 5, 4, 'Blue') ;
4 rows affected
 hidden batch(es)


CREATE FUNCTION fnCF(@Qty decimal, @TTS int) RETURNS varchar(1024) AS BEGIN DECLARE @step int = 0; DECLARE @sv varchar(1024) = ''; DECLARE @Q0 int; DECLARE @Q1 decimal; SET @step = @TTS SET @Q1 = @Qty WHILE @step > 0 BEGIN SET @Q0 = @Q1 / @step; SELECT @sv = @sv + CAST(@Q0 AS varchar(100)) SET @step = @step -1 SET @Q1 = @Q1 - @Q0 IF @step > 0 SET @sv = @sv + ', ' END return @sv; END
 hidden batch(es)


SELECT partid, qtyordered, dividedBy, dbo.fnCF(qtyordered, dividedBy) divInt FROM #Orders;
partid qtyordered dividedBy divInt
SS100 10 3 3, 3, 4
RR200 15 6 2, 2, 2, 3, 3, 3
NN300 3 2 1, 2
OO400 5 4 1, 1, 1, 2
 hidden batch(es)