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 6630449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:24:22+00:00 2026-05-25T22:24:22+00:00

I am looking to write a sql server script to achieve the following in

  • 0

I am looking to write a sql server script to achieve the following in a sql server 2008 database.

I have a number of functions and stored procedures with the following names:

  • prSP_GetItem.1.0.0
  • prSP_GetItem.1.1.0
  • prSp_GetItem.1.2.0

As you can see a version number is appended to them.

Each time a new version of the application is released, new functions/stored procedures are created with the new version number.

What I would like to do is write a generic script to remove all old version of a function or stored procedures. So lets say current version is 1.2.0, all functions and stored procedures ending in a version number before this eg. 1.0.0, 1.1.1 etc should be dropped.

Any tips or ideas how I might write a script to achieve this?

  • 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-05-25T22:24:22+00:00Added an answer on May 25, 2026 at 10:24 pm

    You can use this as starting point and see how far it can take you. Run it against your DB and post your observations. The last select only lists the SQL statement in the last column. Nothing gets executed actually. Verify the output very carefully.

    ;With RawData As
    (
        SELECT
              name
            , SUBSTRING(name, 1, CHARINDEX('.', name) - 1) AS BaseName
            , CAST(REPLACE(SUBSTRING(name, CHARINDEX('.', name), LEN(name) - CHARINDEX('.', name) + 1), '.', '') AS INT) AS IntVersion
        FROM
            sys.objects
        WHERE
            type = 'P'
            AND
            CHARINDEX('.', name) > 0
            AND
            ISNUMERIC(REPLACE(SUBSTRING(name, CHARINDEX('.', name), LEN(name) - CHARINDEX('.', name) + 1), '.', '')) = 1
    )
    ,GroupedData As
    (
        SELECT
              BaseName
            , MAX(CAST(REPLACE(SUBSTRING(name, CHARINDEX('.', name), LEN(name) - CHARINDEX('.', name) + 1), '.', '') AS INT)) AS IntVersion
        FROM
            RawData
        GROUP BY
            BaseName
    )
    SELECT
        *
        , NULLIF(ISNULL(GD.BaseName, ''), ISNULL(GD.BaseName, '-')) + 'DROP PROCEDURE [' + Name + ']' as SQLs
    FROM
        RawData RD
    LEFT JOIN
        GroupedData GD
    ON
        RD.BaseName = GD.BaseName
        AND
        RD.IntVersion = GD.IntVersion
    --WHERE
    --  GD.BaseName IS NULL
    ORDER BY
          RD.BaseName
        , RD.IntVersion
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to write a C# SQL Server wrapper to call some stored procedures.
I'm looking to write a simple proxy server in .NET. Does anyone have any
I have a WinForm application built with VS 2008 (C#) and SQL Server Express
I am trying to write an aggregate udf for using Sql Server 2008 and
I also have a very large table in SQL Server (2008 R2 Developer Edition)
We currently have a 10 year old nasty, spaghetti-code-style SQL Server database that we
I am trying to write a SQL Server query but have had no luck
In SQL Server 7.0, I need to find out which users have write access
We currently have a 10 year old nasty, spaghetti-code-style SQL Server database that we
I have a SQL Server 2005 database which has about 30-40 connections to the

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.