logo
down
shadow

Calling stored procedure from another stored procedure with parameters


Calling stored procedure from another stored procedure with parameters

By : user2956188
Date : November 22 2020, 10:54 AM
like below fixes the issue You can insert the results from the STORED PROCEDURE into a temp table (table variable or temp table) and them select from that table and join onto the Courses table to retrieve the title.
SQL Fiddle DEMO
code :
CREATE TABLE Courses(
  CourseCode VARCHAR(50),
  CourseName VARCHAR(250)
);
INSERT INTO Courses VALUES ('A','AA'), ('B','BB');

CREATE PROCEDURE OtherTeamsSP(
  @StudentID INT,
  @CurrentSmester INT
)
AS
SELECT 'A' CourseCode,
        'FOO' UpdateType,
        1 UpdateId;

CREATE PROCEDURE MyProcedure(
  @StudentID INT,
  @CurrentSmester INT
)
AS
CREATE TABLE #SPOutput(
  CourseCode VARCHAR(50),
  UpdateType VARCHAR(50),
  UpdateId INT
 )

INSERT INTO #SPOutput
EXEC OtherTeamsSP @StudentID, @CurrentSmester

SELECT *
FROM #SPOutput s INNER JOIN
    Courses c ON s.CourseCode = c.CourseCode
DROP TABLE #SPOutput
EXEC MyProcedure 1,2


Share : facebook icon twitter icon
Correct syntax for calling a stored procedure with parameters from within another stored procedure

Correct syntax for calling a stored procedure with parameters from within another stored procedure


By : Richard Watkins
Date : March 29 2020, 07:55 AM
Hope this helps The GO keyword in T-SQL states that a block of t-sql statements ends and executes that block. This means that a variable defined in one block is not longer "in scope" for a statement occurring after that block has been ended/executed with GO.
GO is not actually a transact sql statement:
Calling a stored procedure that takes 2 parameters from inside a stored procedure that takes 1 parameter

Calling a stored procedure that takes 2 parameters from inside a stored procedure that takes 1 parameter


By : Anonimous11111
Date : March 29 2020, 07:55 AM
I wish this help you No you cannot create overloaded stored procedure. One will override the other. Though Overloaded function is possible. So, change the inner stored procedure to some different name or the vice versa (i.e. outer stored procedure). Here is an example that will simulate your situation.
-- Outer stored procedure
code :
USE [Test]
GO

-- exec [dbo].[USP_GetHomeData] 2012
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_GetHomeData]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[USP_GetHomeData]
GO

CREATE PROCEDURE [dbo].[USP_GetHomeData] 
-- Add the parameters for the stored procedure here
(
    @Year INT
)
AS
BEGIN
        DECLARE @startDate DATETIME='1/1/' + CAST(@Year AS VARCHAR(4))  -- mm/dd/yyyy
        DECLARE @endDate DATETIME=GETDATE() -- mm/dd/yyyy

        SELECT [Date] = DATEADD(Day,Number,@startDate) 
        FROM  master..spt_values  WITH(NOLOCK)
        WHERE Type='P'
        AND DATEADD(day,Number,@startDate) <= @endDate

        exec [dbo].[USP_GetHomeData_Inner] '1/1/1900', @endDate
END
USE [Test]
GO

-- exec [dbo].[USP_GetHomeData_Inner] '1/1/1900', '11/25/2012'
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_GetHomeData_Inner]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[USP_GetHomeData_Inner]
GO

CREATE PROCEDURE [dbo].[USP_GetHomeData_Inner] 
-- Add the parameters for the stored procedure here
(
    @startDate DATETIME
    ,@endDate DATETIME
)
AS
BEGIN

        ;WITH Calender AS 
        (
            SELECT @startDate AS CalanderDate
            UNION ALL
            SELECT CalanderDate + 1 FROM Calender
            WHERE CalanderDate + 1 <= @endDate
        )
        SELECT [Date] = CONVERT(VARCHAR(10),CalanderDate,25) 
        FROM Calender WITH(NOLOCK)
        OPTION (MAXRECURSION 0)
END
TSQL- stored procedure dynamically handle varying number of parameters to execute stored procedure per parameter

TSQL- stored procedure dynamically handle varying number of parameters to execute stored procedure per parameter


By : DkM
Date : March 29 2020, 07:55 AM
it should still fix some issue You could do the following:
create a function that would split your string based on a specific delimiter (seems like in this case the delimiter would be a comma
code :
create function [dbo].[split_str]
(
    @parameter nvarchar(max), 
    @delimiter char(1)
)
returns @res table (val nvarchar(max), seq int)
as
begin

set @parameter += @delimiter

;with cte as
(
    select cast(1 as bigint) f, charindex(@delimiter, @parameter) t, 1 seq
    union all
    select t + 1, charindex(@delimiter, @parameter, t + 1), seq + 1
    from cte
    where charindex(@delimiter, @parameter, t + 1) > 0
)
insert @res
select substring(@parameter, f, t - f), seq 
from cte
option (maxrecursion 0)
where ServerName IN dbo.split_str(ServerName, ',')
Calling a stored procedure returning multiple table results inside another stored procedure

Calling a stored procedure returning multiple table results inside another stored procedure


By : Claudia Pisanu
Date : March 29 2020, 07:55 AM
I wish this helpful for you You can use INSERT INTO EXEC for one result set.
But that won't work for multiple result sets.
how to pass in and out parameters to a mysql stored procedure and return the stored procedure result in the nodejs code

how to pass in and out parameters to a mysql stored procedure and return the stored procedure result in the nodejs code


By : Apsara Prabodani
Date : March 29 2020, 07:55 AM
To fix the issue you can do ,
First thing first, set your mysql to accept multiple statement
Related Posts Related Posts :
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org