Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:54:43+00:00 2026-06-15T04:54:43+00:00

I have to write a procedure which is able using a Table version to

  • 0

I have to write a procedure which is able using a Table version to bring the database to a specific moment in type. For instance to move from version 1 to version 10 or the other way around. The thing is I’m pretty blurry with this chapter, and the school course has almost nothing about it. I tried using the internet to build a solution but somehow I got stuck. Please help me understand what am I doing wrong.

Table version, 1 columnm, type int

query

 create procedure [dbo].[goto_vs] (
        @vs int
    )
    as
    begin
        declare @current_vs int, @counter int;
        declare @sqlquery nvarchar(50); --query to modify
        declare @sqlsp nvarchar(30);
        declare @sqlversion nvarchar(3);
        declare @sqlreverse nvarchar(10);

        --get the current version from table
        select @current_vs=version from dbo.version;

        --checking for valid version
        if (@current_vs = @vs) begin
            print('The database is already at this version...')
            return
        end
        else begin
            if (@vs > 5) begin
                print('Setting the version of databse to last one...')
                set @vs = 5
            end
            else begin
                if (@vs < 0) begin
                    print('Setting the database to default...')
                    set @vs = 0
                end
            end
        end

        --setting up the string for exec
        set @sqlsp = 'exec sp_create_table_awards'

        --check if we go further or earlier in time
        print('Changing database version...')
        if (@vs > @current_vs) begin
            set @sqlreverse = ''
            goto upgrading
        end
        else begin
            set @sqlreverse = 'undo_create_awards'
            goto downgrading
        end

        --upgrading code
        upgrading:
            set @counter = @current_vs + 1
            while (@counter <= @vs) begin
                set @sqlquery = @sqlsp + cast(@counter as nvarchar(2)) + @sqlreverse
                print(@sqlquery)
                exec sp_executeSql @sqlquery
                set @counter = @counter + 1
            end
            goto ending
        downgrading:
            set @counter = @current_vs
            while (@counter > @vs) begin
                set @sqlquery = @sqlsp + cast(@counter as nvarchar(2)) + @sqlreverse
                print(@sqlquery)
                exec sp_executeSql @sqlquery
                set @counter = @counter - 1
            end
            goto ending
        ending:
            update dbo.version set version=@vs
            print('Database version changed...')
    end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:54:45+00:00Added an answer on June 15, 2026 at 4:54 am

    Considering I figured a way, and have got no responses, I will post it as a response because it may help other students which studie computer science

    To simplify I named all my procedures by this pattern do_x and undo_x where x is a int where do / undo _x are procedures which pair toughter for example do_1 and undo_1 create a table and destroy a table

    ALTER PROCEDURE [dbo].[goto_vs] 
        -- Add the parameters for the stored procedure here
        @v int = 0
    
    AS
    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON;
    
        -- Insert statements for procedure here
        declare @i int
        declare @toexec nvarchar(70)
    
        set @i = (select version from version)
    
        -- If the requested version is lower than the current one, downgrade.
        while(@i > @v)
            BEGIN
                set @i = @i - 1
                set @toexec = 'Undo_' + CONVERT(varchar,@i);
                exec sp_executeSql @toexec
                print @toexec
            END
    
        -- Otherwise, upgrade.
        while(@i < @v)
            BEGIN
                set @toexec = 'Update_' + CONVERT(varchar, @i);
                exec sp_executeSql @toexec
                set @i = @i + 1
                print @toexec 
            END 
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java stored procedure which fetches record from the table using Resultset
I have a stored procedure in which if I write the following query without
I have to write an Oracle procedure which should invoke an Oracle function returning
I am trying to write a stored procedure which selects columns from a table
I have a database which has two tables. One table contains the information of
I have to write one Stored Procedure, In which I have to find the
I am using SQL Server 2008, and in my database I have a table
I have to write a update stored procedure. I will be asking paramters for
I want to write a comparation procedure (t-sql) for site seo. I have a
I have a stored procedure (that I didn't write) that uses openquery to populate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.