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

  • Home
  • SEARCH
  • 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 1009933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:00:18+00:00 2026-05-16T09:00:18+00:00

In my stored procedure I have to pass a table and column name which

  • 0

In my stored procedure I have to pass a table and column name which may change everytime. So I build command and execute it. I want the output in another variable @curr_id. This store procedure will be called by second stored procedure by using @curr_id as input.

My problem is populating the @curr_id vriable. It is returned as zero. If I remove the
curr_id variable then it works(see commented line)

Can someone pl. tell me
– how to get @curr_id populated and returned as OUTPUT?
– how to call the first stored proc from a second stored proc?

ALTER PROCEDURE [dbo].[sp_astm_getcurrid]
@ColName as nvarchar(250),
@TblName as nvarchar(250),
@curr_id nvarchar(max) OUTPUT 
AS
BEGIN
DECLARE @cmd nvarchar(max)

SET @cmd =N'SET '+@curr_id+'= SELECT MAX('+@ColName+') FROM '+@TblName;
--SET @cmd =N'SELECT MAX('+@ColName+') FROM '+@TblName;

EXEC (@cmd)

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-05-16T09:00:19+00:00Added an answer on May 16, 2026 at 9:00 am
    Friend Function execSP(ByVal spName As String, Optional ByVal params As Collection = Nothing) As Integer
            Dim cmd As SqlCommand
            Dim param As SqlParameter
            Dim ret As Integer
            Dim iParam As Integer
    
            cmd = New SqlCommand
            cmd.CommandText = spName
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = _sqlConn
            cmd.CommandTimeout = 0
    
            If Not params Is Nothing Then
                For iParam = 1 To params.Count
                    param = params(iParam)
                    cmd.Parameters.Add(param)
                Next
            End If
    
            If _sqlConn.State <> ConnectionState.Open Then
                _sqlConn.Open()
            End If
    
            Try
                ret = cmd.ExecuteNonQuery()
            Catch ex As Exception
                Throw New Exception(ex.Message)
            Finally
                _sqlConn.Close()
            End Try
            Return ret
        End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure in MySQL that should update a column in a
I have a stored procedure in SQL Server with try catch. What I want
I am having the stored procedure. For that i need to pass the Database
just a quick question here. Lets say I have a stored procedure for seleting
I've a stored procedure here ALTER PROCEDURE [dbo].[SortedReport] ( @ClientID INT, @RecordLimit, @FromDate DATETIME,
I have a table containing a student-grade relationship: Student Grade StartDate EndDate 1 1
Below is a simplified example of a stored procedure I've created. DELIMITER // CREATE
Please help with my final project in my intro/intermediate programming class. Using stored procedures,table
I'm looking for suggestions for scaling a points leaderboard system. I already have a
I'm trying to implement a REST service using WCF which will take the parameters

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.