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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:51:04+00:00 2026-05-23T00:51:04+00:00

Using MS SQL2000 at present if that makes any difference. Is there a better

  • 0

Using MS SQL2000 at present if that makes any difference.

Is there a better way than the method below to be able to programatically access a table ?

declare @tableName as varchar(50)
declare @sql varchar(4000)

set @tableName = 'User'

print @tableName

If EXISTS(
select TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_name = ''+@TableName+''
)
BEGIN
    set @sql = 'select * from [' + @tableName + ']'
    exec(@sql)

end

Essentially Im trying to create a simple Mapping tool for CRUD operations so that I need only one Sproc for each operation, and I can pass in my parameterised object, a table name and let the database do the rest. This is purely for my own personal education, hence why Im not using an established framework, so if there are any major gotcha’s with my idea or the code above, I’d appreciate knowing as well.

Thanks

  • 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-23T00:51:05+00:00Added an answer on May 23, 2026 at 12:51 am

    This is complete example to create a SP by follow your initial code:

    CREATE PROCEDURE dbo.CustomSelect (@tableName as varchar(50))
    AS 
    SET NOCOUNT ON
    DECLARE @sql varchar(4000)
    
    If EXISTS(
    select TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_name = @tableName
    )
    BEGIN
        set @sql = 'select 1 as Found, * from [' + @tableName + ']'
        exec(@sql)
    END
    ELSE
    BEGIN
        select 0 as Found
    END
    

    This SP always return a recordset so you can check the value of the field FOUND to know if the table exist or not

    usage:

    EXEC CustomSelect 'User'
    

    Hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using CF8 and SQL2000. I'm storing a bunch of HTML in a Text
Is it possible to create LIGHTWEIGHT transactions using TransactionScope() with SQL2000? Or if not,
Using online interfaces to a version control system is a nice way to have
I'm using the below query to return results from a table using Full-Text-Search. In
I'm looking for any advice on what's the optimum way of inserting a large
We have a 3rd-party app that wants to call a stored proc using SQL
I've created an XML file using the .Save() method of an ADODB recordset in
I have a VB6 project that is using a SQL2008 database. The project consists
Using Microsoft Sql 2000 I have a requirement to be able to email a
Hello Im using SQL2000 so I build a Dynamic Query and in the last

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.