Progress Bar Simulation on SQL Server

  • Comments posted to this topic are about the item Progress Bar Simulation on SQL Server

  • Unfortunately I do not understand the language of the article but surely you can use the REPLICATE function to populate your pipe symbols...

    e.g.SET @exec1 = 'update a set progreso=replicate(''|'','+@c+'),descrip = (select ''Progreso ... ''+convert(varchar(10),'+ @C +')+'' % Creditos ™ : Richard J.Chero Díaz '') from progress awhere descrip like ''Progreso%''

    '

  • Thank you very much for reply

    I try Replicate commnad and that´s better to optimize the script. 😉

  • modified code 😀

    -- ======================================================

    -- Author:[Chero Díaz,Richard Johnnatan]

    -- DBA.

    -- Create date: [2013,11,28]

    -- Description:[Simulación de Barra de Progreso]

    -- © Copyright - Todos los Derechos reservados ™

    -- ======================================================

    ---__________________________________________________________---

    --- Creando e insertando registros a mi tabla Conteo ---

    ---__________________________________________________________---

    --- Eliminamos la tabla si existe

    if exists (select * from sysobjects

    where id = object_id(N'[dbo].[conteo]') and OBJECTPROPERTY(id, N'IsTable') = 1)

    drop table [dbo].[conteo]

    --- Creamos tabla de conteo es decir los rangos de progreso

    CREATE TABLE conteo (progreso int)

    --- Inserto el primer valor de progreso en mi tabla conteo

    insert into conteo values ('1')

    --- Inserto los 100 valores en mi tabla conteo dinamicamente

    WHILE (select max(progreso)+1 from conteo where progreso < 101) < 101

    BEGIN

    insert into conteo select max(progreso)+1 from conteo where progreso < 101

    END

    --- select * from conteo

    /*_______________________________________________________________________________________*/

    ---__________________________________________________________---

    --- Creando e insertando registros a mi tabla progress ---

    ---__________________________________________________________---

    --- Eliminamos la tabla si existe

    if exists (select * from sysobjects

    where id = object_id(N'[dbo].[progress]') and OBJECTPROPERTY(id, N'IsTable') = 1)

    drop table [dbo].[progress]

    --- Creamos tabla de fechas es decir los dias del mes

    CREATE TABLE progress (progreso varchar(255),descrip varchar(255))

    --- Insertamos registro 0

    insert into progress values(' ','Progreso ... 0 % Creditos ™ : Richard J.Chero Díaz ')

    ---select * from progress

    /*_______________________________________________________________________________________*/

    ---Cursor Progreso

    -- variable ----------------------------------------------

    DECLARE @PROGRESO nvarchar(255)

    -- variables para definir las consultas en tiempo de ejecución ------------------

    DECLARE @exec1 nvarchar(4000)

    DECLARE @exec2 nvarchar(4000)

    DECLARE @exec3 nvarchar(4000)

    -- declarar el cursor -----------------------------------------------------------

    DECLARE RECORRE CURSOR FOR

    SELECT * from conteo

    -- abrir cursor -----------------------------------------------------------------

    OPEN RECORRE

    FETCH NEXT FROM RECORRE INTO @PROGRESO

    -- mientras haya datos... -------------------------------------------------------

    WHILE @@FETCH_STATUS = 0

    BEGIN

    -- por cada fila ----------------------------------------

    declare @b-2 as varchar(100)

    declare @C as varchar(100)

    set @b-2 = @PROGRESO

    set @C = @b-2

    SET @exec1 = 'update a set progreso=replicate(''|'','+@c+'),descrip = (select ''Progreso ... ''+convert(varchar(10),'+ @C +')+'' % Creditos ™ : Richard J.Chero Díaz '') from progress awhere descrip like ''Progreso%''

    '

    IF (select @C)<101

    BEGIN

    print @exec1

    EXECUTE (@exec1)

    END

    -- ======================================================

    -- Author:[Chero Díaz,Richard Johnnatan]

    -- DBA.

    -- Create date: [2013,11,28]

    -- Description:[Simulación de Barra de Progreso]

    -- © Copyright - Todos los Derechos reservados ™

    -- ======================================================

    select * from [progress]

    -----------------------------------------------------------------------------------

    ------ siguiente registro ---------------------------------------------------------

    FETCH NEXT FROM RECORRE INTO @PROGRESO

    END

    -- cerrar y liberar la memoria del cursor -----------------------------------------

    CLOSE RECORRE

    DEALLOCATE RECORRE

  • Interesting.

    You could also do something like this:

    WITH CTE AS

    (

    SELECT

    1 AS number

    UNION ALL

    SELECT

    X.number + 1 AS number

    FROM

    CTE X

    WHERE

    X.number + 1 <= 100

    )

    SELECT

    REPLICATE ('|', X.number) + REPLICATE ('.', 100 - X.number) AS progress_bar

    ,CONVERT (VARCHAR (11), X.number) + '%' AS progress_pct

    FROM

    CTE X

  • Excellent,:-)

    thank you very much ..!!!

  • Neat concept. 🙂

  • Sean Smith-776614 (12/11/2013)


    Interesting.

    You could also do something like this:

    WITH CTE AS

    (

    SELECT

    1 AS number

    UNION ALL

    SELECT

    X.number + 1 AS number

    FROM

    CTE X

    WHERE

    X.number + 1 <= 100

    )

    SELECT

    REPLICATE ('|', X.number) + REPLICATE ('.', 100 - X.number) AS progress_bar

    ,CONVERT (VARCHAR (11), X.number) + '%' AS progress_pct

    FROM

    CTE X

    Excellent and much neater code ..... :w00t:

    ______________________________________________________________________________________________________________________________________________________________________________________
    HTH !
    Kin
    MCTS : 2005, 2008
    Active SQL Server Community Contributor 🙂

  • other way to make progress bar for each 10% only

    declare

    @max-2 decimal(10,3)

    , @CNT decimal(10,3)

    , @ProgressBar varchar(250)

    , @Percentage int

    , @PercentageStep int

    set @max-2 = 8745.458

    set @CNT = 1.0

    set @PercentageStep = 10

    WHILE @CNT <= @max-2

    BEGIN

    Set @CNT = @CNT + 1

    IF ((@CNT*100/(ceiling(@MAX/@PercentageStep)*@PercentageStep)) % @PercentageStep) in ( 0.00)

    BEGIN

    set @Percentage = @CNT*100/(ceiling(@MAX/@PercentageStep)*@PercentageStep)

    set @ProgressBar = replicate('X',@Percentage/2)+' '+ltrim(rtrim(str(@Percentage)))+' '+replicate('_',(100-@Percentage)/2)

    raiserror(@ProgressBar, 0, 1) with nowait

    END

    END

  • This is a neat idea, but am I missing something? How would one put this into use as an actual progress bar? For example, to estimate how far along you are on a long running update query?

  • At the very least it's just a cool concept. 🙂

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply