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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:50:48+00:00 2026-05-31T12:50:48+00:00

I am having problems removing a temp table in SQL server. I have a

  • 0

I am having problems removing a temp table in SQL server.

I have a stored procedure but when I run in via my application it says:

“There is already an object named ‘#WeekList’ in the database”

when i try to drop the table i get the following message:

Cannot drop the table ‘#WeekList’, because it does not exist or you do
not have permission.

My SP is as follows:

USE [test_staff]
GO
/****** Object:  StoredProcedure [dbo].[sp_create_week_list]    Script Date: 03/20/2012 09:35:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



ALTER PROCEDURE [dbo].[sp_create_week_list]

AS

CREATE TABLE #WeekList
    (
    month_date date
    )


DECLARE @REPORT_DATE DATETIME, @WEEK_BEGINING VARCHAR(10)
SELECT @REPORT_DATE = '2011-01-19T00:00:00'
--SELECT @REPORT_DATE = GETDATE() -- should grab the date now.
SELECT @WEEK_BEGINING = 'MONDAY'
IF @WEEK_BEGINING = 'MONDAY'
SET DATEFIRST 1
ELSE IF @WEEK_BEGINING = 'TUESDAY'
SET DATEFIRST 2
ELSE IF @WEEK_BEGINING = 'WEDNESDAY'
SET DATEFIRST 3
ELSE IF @WEEK_BEGINING = 'THURSDAY'
SET DATEFIRST 4
ELSE IF @WEEK_BEGINING = 'FRIDAY'
SET DATEFIRST 5
ELSE IF @WEEK_BEGINING = 'SATURDAY'
SET DATEFIRST 6
ELSE IF @WEEK_BEGINING = 'SUNDAY'
SET DATEFIRST 7
DECLARE @WEEK_START_DATE DATETIME, @WEEK_END_DATE DATETIME
--GET THE WEEK START DATE
SELECT @WEEK_START_DATE = @REPORT_DATE - (DATEPART(DW, @REPORT_DATE) - 1)
--GET THE WEEK END DATE
SELECT @WEEK_END_DATE = @REPORT_DATE + (7 - DATEPART(DW, @REPORT_DATE))
PRINT 'Week Start: ' + CONVERT(VARCHAR, @WEEK_START_DATE)
PRINT 'Week End: ' + CONVERT(VARCHAR, @WEEK_END_DATE)

DECLARE @Interval int = datediff(WEEK,getdate(),@WEEK_START_DATE)+1

SELECT Start_Week=@WEEK_START_DATE
, End_Week=@WEEK_END_DATE
INTO #WeekList

WHILE @Interval <= 0
    BEGIN
    set @WEEK_START_DATE=DATEADD(WEEK,1,@WEEK_START_DATE)
    set @WEEK_END_DATE=DATEADD(WEEK,1,@WEEK_END_DATE)
    INSERT INTO #WeekList values (@WEEK_START_DATE,@WEEK_END_DATE)
    SET @Interval += 1;
    END

SELECT 
CONVERT(VARCHAR(11), Start_Week, 106) AS 'Start',
CONVERT(VARCHAR(11), End_Week, 106) AS 'End',
DATEDIFF(DAY, 0, Start_Week) / 7 AS week_ref   -- create the unique week reference number

FROM #WeekList
ORDER BY Start_Week DESC

DROP TABLE #WeekList
  • 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-31T12:50:50+00:00Added an answer on May 31, 2026 at 12:50 pm

    In the SP there is a problem in following statement.

    SELECT Start_Week=@WEEK_START_DATE
    , End_Week=@WEEK_END_DATE
    INTO #WeekList
    

    Instead of that try this one, it may work.

    INSERT INTO #WeekList
    SELECT Start_Week=@WEEK_START_DATE
    , End_Week=@WEEK_END_DATE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems when it comes to removing a row from a table.
Im having problems with classpaths. I have used them before with import but I'm
I have a simple database table (SQL Server 2008 R2 Express), which has a
I have the standard XML form and am having problems removing an element. XML
Im having problems building a query with the linq to sql data query expression
I have recently started having problems with TortoiseCVS, or more specifically with plink, the
I'm having some problems removing clients from a channellist. This is the code i
I am having problems displaying images which have been queried from the database. The
I'm having problems removing a vector from a multidimensional vector I would like to
Im having problems with removing items from an arraylist using an iterator. My aim

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.