开发者

Not able to get INSERT of SP to work

开发者 https://www.devze.com 2023-03-26 11:51 出处:网络
I am not able to get the INSERT portion of the below procedure to work. Any help would be appreciated....

I am not able to get the INSERT portion of the below procedure to work. Any help would be appreciated....

@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 int,
@GUID varchar(250) = Null

        AS

        BEGIN

        SET NOCOUNT ON;    

        DECLARE @submitDate1 DATETIME;
        SET @submitDate1 = GETDATE()
        SET @prev_LangString = @original_lang_String

        DECLARE @sql NVARCHAR(MAX);

        SELECT @sql = N' UPDATE  ' + QUOTENAME(@currTable) + ' SET [lang_Str开发者_JAVA技巧ing] = ''' + REPLACE(@lang_String,'''','''''') + ''', [date_Changed] = ''' +  convert(varchar(20), @submitDate1) + ''', [prev_LangString] = ''' + @prev_LangString + ''', [needsTranslation] = ''' + @needsTranslation + ''' 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 

I tried this code block only and no luck it did not INSERT to tblPendingDBUpdates.... Noticed something weird about GUID as field name so changed it in table also...

        AS

        BEGIN

        SET NOCOUNT ON;    

        DECLARE @submitDate1 DATETIME;
        SET @submitDate1 = GETDATE()
       -- SET @prev_LangString = @original_lang_String

        DECLARE @sql NVARCHAR(MAX);

        DECLARE @currTable varchar(100);
        SET @currTable = 'tblLangenUS'
        DECLARE @ID INT;
        SET @ID = 2
        DECLARE @short_Text varchar(250);
        SET @short_Text = 'testing99'
        DECLARE @StringID_from_Master INT;
        SET @StringID_from_Master = 2    

        DECLARE @lang_String varchar(250);
        SET @lang_String = 'testing9999'
        DECLARE @GUID1 varchar(250);
        SET @GUID1 = 'Null'


            INSERT tblPendingDBUpdates    
                (      stringMasterID,
                       databaseName,
                       databaseStringID,
                       englishText,
                       foreignLangText,
                       submitDate,
                       GUID1
                )  

            SELECT      @StringID_from_Master,
                        Database_Name,
                        dbKeyID_ofStringName,
                        @short_Text,
                        @lang_String,
                        @submitDate1,
                        @GUID1    
            FROM      tblDBUsage      
            WHERE tblUniquetblStringsMaster_ID = @StringID_from_Master;


            END 


I don't really know what you need but here is a stored proc with your declarations

CREATE PROCEDURE TestProc
    AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @submitDate1 DATETIME
        SET @submitDate1 = GETDATE()
    DECLARE @sql NVARCHAR(MAX)
    DECLARE @StringID_from_Master INT
        SET @StringID_from_Master = 2  
    DECLARE @short_Text varchar(250)
        SET @short_Text = 'testing99' 
    DECLARE @lang_String varchar(250)
        SET @lang_String = 'testing9999'
       DECLARE @GUID1 varchar(250)
        SET @GUID1 = 'Null'

    BEGIN 
        EXEC sp_executesql @sql
    END

    BEGIN 
        INSERT INTO tblPendingDBUpdates 
        (
            stringMasterID,
            databaseName,
            databaseStringID,
            englishText,
            foreignLangText,
            submitDate,
            GUID1
        )
        SELECT  
            @StringID_from_Master,
            Database_Name,
            dbKeyID_ofStringName,
            @short_Text, 
            @lang_String, 
            @submitDate1,
            @GUID1
        FROM tblDBUsage
        WHERE tblUniquetblStringsMaster_ID = @StringID_from_Master
    END
END
GO


Well as far I understand it ... change the SP code to below and try again ... most probably will work fine

CREATE PROCEDURE <SOME NAME>
AS
BEGIN

 <ALL YOUR DECLARATION HERE>

BEGIN

EXEC sp_executesql @sql;
END

GO

BEGIN

INSERT INTO tblPendingDBUpdates 
(stringMasterID,
databaseName,
databaseStringID,
englishText,
foreignLangText,
submitDate,
GUID1)
SELECT  @StringID_from_Master,
Database_Name,
dbKeyID_ofStringName,
@short_Text, 
@lang_String, 
@submitDate1,
@GUID1
FROM tblDBUsage
WHERE tblUniquetblStringsMaster_ID = @StringID_from_Master; 
END  
END
GO


If your not getting an error message and inserting zero rows, than you select statement must not be returning anything.

what does this return?

select *
FROM      tblDBUsage      
WHERE tblUniquetblStringsMaster_ID = @StringID_from_Master

If you're first stored proc it didn't look like @StringID_from_Master ever got set. That could be your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消