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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:37:02+00:00 2026-06-08T10:37:02+00:00

This procedure has three parameters. But when I try to execute by passing parameters

  • 0

This procedure has three parameters. But when I try to execute by passing parameters it shows me an error. Please help me.

create procedure queryfunctions @Tabname varchar(150),@colname varchar(150),@valuesname varchar(150)
as
begin
declare @sql varchar(4000)
select @sql='select * from @Tabname where @colname=@valuesname'
exec(@sql)
end

exec queryfunctions 'education','eduChildName','Revathi'

Error :

Msg 1087, Level 15, State 2, Line 1
Must declare the table variable “@Tabname”.

  • 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-08T10:37:04+00:00Added an answer on June 8, 2026 at 10:37 am

    Here is a much safer alternative:

    ALTER PROCEDURE dbo.queryfunctions 
      @Tabname NVARCHAR(511),
      @colname NVARCHAR(128),
      @valuesname VARCHAR(150)
    AS
    BEGIN
      SET NOCOUNT ON;
    
      DECLARE @sql NVARCHAR(MAX);
    
      SET @sql = 'SELECT * FROM ' + @Tabname 
               + ' WHERE ' + QUOTENAME(@colname) + ' = @v';
    
      EXEC sp_executesql @sql, N'@v VARCHAR(150)', @valuesname;
    END
    GO
    
    EXEC dbo.queryfunctions N'dbo.education', N'eduChildName', 'Revathi';
    

    What did I change?

    1. Always use dbo prefix when creating / referencing objects.
    2. Table and column names are NVARCHAR and can be longer than 150 characters. Much safer to allow the parameters to accommodate a table someone might add in the future.
    3. Added SET NOCOUNT ON as a guard against network overhead and potentially sending erroneous result sets to client.
    4. @sql should always be NVARCHAR.
    5. Use QUOTENAME around entity names such as tables or columns to help thwart SQL injection and also to guard against poorly chosen names (e.g. keywords).
    6. Use proper parameters where possible (again to help thwart SQL injection but also to avoid having to do all kinds of escaping of delimiters on string parameters).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I'm getting this error when I try to execute this procedure. The thing
I have a stored procedure that has this line: SET @SQL = 'SELECT path,title,tags
I've call a stored procedure (SQL Server 2005) in Excel 2007. This SP has
I have a SQL Server 2008 database. This database has a stored procedure that
This problem has driven me mad for over a day now. I can create
Now I know this has been asked before. But I've made doubly sure that
I have this procedure i my package: PROCEDURE pr_export_blob( p_name IN VARCHAR2, p_blob IN
I want to call this procedure that sends one value that can be NULL
I have this procedure that executes another procedure passed by a parameter and its
Below is my Oracle Procedure. When i call this procedure using java, it throws

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.