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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:33:40+00:00 2026-05-19T02:33:40+00:00

I have a stored procedure that is called by data collection system . The

  • 0

I have a stored procedure that is called by data collection system.

The procedure has many parameters that for the collected data.

I’m using the INFORMATION_SCHEMA to pull the parameter list into a temp table

    SELECT substring(PARAMETER_NAME , 2 , len(PARAMETER_NAME ) - 1) 'SpParam', PARAMETER_NAME, DATA_TYPE
    INTO #tempParam
    FROM INFORMATION_SCHEMA.PARAMETERS
    WHERE SPECIFIC_NAME='InsertB2ChamberData'   

From there I can insert any missing data tag names in my tag list table

    INSERT INTO ToolTag
    SELECT @ToolID, @ToolTagTypeID, SpParam, 'Default Description', GETDATE()
    FROM #tempParam
    WHERE spParam NOT IN (SELECT ToolTagName FROM ToolTag WHERE ToolID = @ToolID)

So far so good, now I would like to use the ToolTag and the temp table list to insert the data from each parameter. Initial I though some dynamic SQL would do the trick.

    DECLARE tag CURSOR FOR 
    SELECT t.ToolTagID, p.PARAMETER_NAME, p.DATA_TYPE
    FROM ToolTag t
        JOIN #tempParam p
            ON t.ToolTagName = p.SpParam

    OPEN tag

    FETCH NEXT FROM tag INTO @TagID, @Parameter, @DataType

    WHILE @@FETCH_STATUS = 0
    BEGIN

        SELECT @Cindex = CHARINDEX('char', @DataType)
        IF @Cindex  0
        begin

            SELECT @sql = 
            N'INSERT INTO ToolTagData VALUES('+convert(varchar(10),@TagID)+', '+convert(varchar(10),@ToolDataEventID)+', '+ @Parameter +', 0)'
        end
        else
        begin
            SELECT @sql = 
            N'INSERT INTO ToolTagData VALUES('+convert(varchar(10),@TagID)+', '+convert(varchar(10),@ToolDataEventID)+', CONVERT(varchar(255),'+@Parameter +'), '+convert(varchar(50),@Parameter)+')'

        end

        EXEC(@sql)

        FETCH NEXT FROM tag INTO @TagID, @Parameter, @DataType
    END

    CLOSE tag
    DEALLOCATE tag

Of course the above doesn’t work as the @sql statement ends up with something like this:

INSERT INTO ToolTagData VALUES(315, 50, @ShutterPosition, 0)

As opposed to the @ShutterPosition parameter value. I’m stuck here, I could so some kind of brute force with each name, but I’d like to be able to be abstract and have re-usability for other procedures.

So is there any way out this, or am I barking up the wrong tree with this approach?

EDIT:
My Schema looks like this:
alt text

The goal is to insert one record into ToolTagData Data for each stored procedure parameter. The key into ToolTag is the name of the stored procedure parameter.

The hope is that tags are added to the ToolTag table simply by adding a new parameter to procedure.

I’m limited by what the third party data acquisition program can do, so this an attempt abstract the process.

  • 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-19T02:33:40+00:00Added an answer on May 19, 2026 at 2:33 am

    In the end I’ve decide to use a CLR stored procedure to implement this:

    var tags = new
                                               {
                                                       @Tag1,
                                                       @Tag2,
                                                       ...
                                                       @LastTag};
    
                 using (var conn =
                          new SqlConnection("context connection = true"))
                 {
                          conn.Open();
                          var cmd = new SqlCommand
                                                      {
                                                               Connection = conn,
                                                               CommandText =
                                                                        "INSERT INTO TagGroupData SELECT TagGroupID , GETDATE() FROM TagGroup WHERE TagGroupName = 'L1Data' SELECT SCOPE_IDENTITY()"
                                                      };
    
                          var tagGroupDataId = cmd.ExecuteScalar();
    
                          cmd.CommandText = "";
    
    
                          cmd.Parameters.Add("@Data", SqlDbType.Float);
                          cmd.Parameters.Add("@Name", SqlDbType.VarChar, 100);
                          cmd.Parameters.Add("@tg", SqlDbType.Int);
    
                          cmd.Parameters[2].Value = tagGroupDataId;
    
                          cmd.CommandText =
                                   "INSERT INTO ToolTagData SELECT t.ToolTagID, CONVERT(varchar(255),@Data), @Data, @tg, GETDATE() FROM ToolTag t WHERE t.ToolTagName = @Name";
    
                          foreach (PropertyInfo pi in tags.GetType().GetProperties())
                          {
                                   cmd.Parameters[1].Value = pi.Name;
                                   cmd.Parameters[0].Value = pi.GetValue(tags, null);
    
                                   cmd.ExecuteScalar();
                          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using entity framework 4. I have a stored procedure that just updates one
I have a stored procedure that is called by another stored procedure ALTER PROCEDURE
I'm working on a stored procedure. I have a table called #CashFlow that contains
I have stored procedures in SQL Server T-SQL that are called from .NET within
I have a strange, sporadic issue. I have stored procedure that returns back 5
I have a stored procedure that consists of a single select query used to
I have a stored procedure that returns multiple tables. How can I execute and
I have a stored procedure that looks like: CREATE PROCEDURE dbo.usp_TestFilter @AdditionalFilter BIT =
I have a Stored Procedure that rolls-back a series of operations. I want to
I have a stored procedure that returns values from a temp table. In my

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.