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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:25:01+00:00 2026-05-22T19:25:01+00:00

I need to write a procedure which will have just execute statements. Example: Create

  • 0

I need to write a procedure which will have just execute statements.

Example:

Create Procedure dbo.allSPExecute( @id int)
as
begin

EXEC dbo.tic @day= 7,@name = 'Gname',@Type = 'Utype'
EXEC dbo.tic @day= 7,@name = 'tname',@Type = 'Utype'
EXEC dbo.gtype @day = 7,@Tname = 'UName_By',@Udept = 'Dept'

End

I have more than 50 statements like this.I have a Table which is Lookup:

ID  Name        SCol      Dcol       IOrd
1   dbo.tic     Gname     @name       1
1   dbo.tic     tname     @name       2
1   dbo.tic     Utype     @Type       1
1   dbo.tic     Utype     @Type       2
2   dbo.gtype   UName_By  @Tname      1
2   dbo.gtype   Dept      @Udept      1

Is there a way so that If i pass ID then it will take the values from the Lookup table and execute the procedure. Can anyone help?

EDIT: Changed the Data from Lookpup table and Create Procedure

  • 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-22T19:25:02+00:00Added an answer on May 22, 2026 at 7:25 pm

    here is a solution that does not need cursors. I am using FOR XML keyword to concatenate strings together. I am doing this in two places – once for concatenating the list of parameters, and once for concatenating all the individual exec statements. I haven’t tested this though, but i think this should be much faster than using cursors

    CREATE PROCEDURE dbo.allSPExecute( @id INT ) 
    AS  
    BEGIN   
      DECLARE @query VARCHAR(MAX);   
      SELECT @query =   (
        SELECT ExecPart + ' ' + SUBSTRING(Params,2,LEN(Params)) + CHAR(10)
        FROM
        (
          SELECT 
            ExecPart ='EXEC ' +(SELECT TOP 1 Name FROM MyTable WHERE ID = @id) ,
            Params = (SELECT ', ' + Dcol + ' = ' + Scol 
                      FROM MyTable t1 WHERE ID = @id AND t1.IOrd = t.IOrd FOR XML PATH(''))
          FROM MyTable t
          WHERE ID = @id
          GROUP BY IOrd
        ) t
        FOR XML PATH('')   
      ) 
    
      EXEC (@query) 
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a stored procedure which will get destination IP and then
i need to write a stored procedure which will return a string.logic is when
I need to write a Stored procedure in SQL server whose data returned will
I need to write a program used internally where different users will have different
I need write an update statement that used multiple tables to determine which rows
I have an access database file (test.mdb) and I need to write a stored
I have a stored procedure which is returning me about 50 columns. I want
I have a SQL table called StudentMarks.which consist of StudentID,SubjectName,SubjectMark I want to write
I want to write a stored procedure that queries XML files after I have
I am trying to write a stored procedure which selects columns from a table

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.