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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:04:27+00:00 2026-05-24T05:04:27+00:00

Here goes, second post, first didn’t go to well…. I am calling an SP

  • 0

Here goes, second post, first didn’t go to well….

I am calling an SP from a Gridview in ASP. I pass in a table name as a variable along with some other variables. I need to UPDATE my original table that the Gridview attaches to but also build a Datalist, I have used a Fetch and got it working fine. Cycle through those records and INSERT data into third table. I was told (in first post) I need to build the SQL string first then execute it. when I write it that way the second part of the insert does not work.

Here is the code in its sliced up form because of efforts to find a succesfull structure….

    @currTable varchar(100),
    @ID int,
    @short_Text varchar(250),
    @brief_Descrip varchar(250) = Null,
    @needsTranslation varchar(10) = Null,
    @prev_LangString varchar(250) = Null,
    @lang_String varchar(250) = Null,
    @original_lang_String varchar(250) = Null,
    @StringID_from_Master varchar(250),     
    @GUID varchar(250) = Null

/*

*/

AS        
SET NOCOUNT ON;

DECLARE @userTable AS VARCHAR(200);
SET @userTable = @currTable
DECLARE @submitDate1 DATETIME;
SET @submitDate1 = GETDATE()



SET @prev_LangString = @original_lang_String
SET @needsTranslation = 'false'

DECLARE @sql varchar(max)
    -- Establish update to the language tabel of user and prepare to search DB for all strings that will need to be updated.
BEGIN

--  DECLARE @sql nvarchar(4000)
SELECT @sql = ' UPDATE  ' + @currTable + 
              ' SET [lang_String] = ' + @lang_String + 
              ' WHERE (ID = ' + @ID + ' ';

EXEC sp_executesql @sql, N'@ID nvarchar(10)', @ID                


        --  UPDATE       @userTable
        --  SET                [lang_String] = @lang_String, [date_Changed] = @submitDate1, [prev_LangString] = @prev_LangString, [needsTranslation] = @needsTranslation, [brief_Descrip] =  @brief_Descrip
        --  WHERE        (ID = @ID)

END

BEGIN               
    DECLARE usedIN_DBScursor CURSOR
    FOR
    SELECT       tblUniquetblStringsMaster_ID, Database_Name, dbKeyID_ofStringName
    FROM         tblDBUsage
    WHERE        (tblUniquetblStringsMaster_ID = @StringID_from_Master );


                -- Declare the variables to store the values returned by FETCH.
    DECLARE @tblUniquetblStringsMaster_ID AS INT;
    DECLARE @dbKEYID as INT;
    DECLARE @dbName as varchar(100);

    OPEN usedIN_DBScursor;

    -- Perform the first fetch and store the values in variables.
    -- Note: The variables are in the same order as the columns
    -- in the SELECT statement. 

    FETCH NEXT FROM usedIN_DBScursor
    INTO @tblUniquetblStringsMaster_ID, @dbName, @dbKEYID;

    -- Check @@FETCH_STATUS to see if there are any more rows to fetch.
    WHILE @@FETCH_STATUS = 0
    BEGIN
    -- Update pending strings table with translation.           
        BEGIN
            INSERT INTO tblPendingDBUpdates
                                     (stringMasterID, databaseName, databaseStringID, englishText, foreignLangText, submitDate, GUID)
            VALUES        (@StringID_from_Master, @dbName, @dbKEYID, @short_Text, @lang_String, @submitDate1, @GUID);                                       
        END 
--      SET @sql = ''
    -- This is executed as long as the previous fetch succeeds.
        FETCH NEXT FROM usedIN_DBScursor
        INTO @tblUniquetblStringsMaster_ID, @dbName, @dbKEYID;
    END

    CLOSE usedIN_DBScursor;
    DEALLOCATE usedIN_DBScursor;    

END 



RETURN
  • 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-24T05:04:27+00:00Added an answer on May 24, 2026 at 5:04 am

    It seems that your procedure could be re-written as follows:

    ALTER PROCEDURE dbo.procedure_name
        @currTable varchar(100),
        @ID int,
        @short_Text varchar(250),
        @brief_Descrip varchar(250) = Null,
        @needsTranslation varchar(10) = Null,
        @prev_LangString varchar(250) = Null,
        @lang_String varchar(250) = Null,
        @original_lang_String varchar(250) = Null,
        @StringID_from_Master varchar(250),     
        @GUID varchar(250) = Null
    AS
    BEGIN
        SET NOCOUNT ON;
    
        DECLARE @sql NVARCHAR(MAX);
    
        SELECT @sql = N' UPDATE  ' + QUOTENAME(@currTable) + ' SET [lang_String] = ''' 
            + REPLACE(@lang_String,'''','''''') + ''' WHERE ID = ' + RTRIM(@ID) + ';';
    
        EXEC sp_executesql @sql;
    
        INSERT tblPendingDBUpdates
        (
          stringMasterID, 
          databaseName,
          databaseStringID,
          englishText,
          foreignLangText,
          submitDate,
          [GUID]
        )
        SELECT
          @StringID_from_Master,
          Database_Name,
          dbKeyID_ofStringName,
          @short_Text,
          @lang_String,
          @submitDate1,
          @GUID
        FROM
          tblDBUsage
          WHERE tblUniquetblStringsMaster_ID = @StringID_from_Master;
    END 
    GO
    

    However, I am not sure why you need a cursor in your original version, or what you mean by “does not work.” Can you explain?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First post, so here goes. I'm writing a script that does intelligent search and
Weird to describe but here goes. I have a table with several rows. One
Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might
first post here so sorry for the length of it. I've been lurking and
Ok here goes: I have a SELECT drop down option with US state names
I assume this is pretty easy so here goes; I'm trying to execute these
I'm not sure if this is even possible but here goes: Currently I have
Ok, here goes. I've completed a Cocoa foundation-tool that calculates mean absolute deviation of
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
Alright, here goes. I'm making a very basic app, and I want the user

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.