• river1 (3/28/2014)


    Hi,

    I'm doing this query:

    DECLARE @TESTE BIGINT

    DECLARE @DB VARCHAR(100)

    SET @DB ='SGCTCENTRAL'

    SET @TESTE = ('SELECT MAX(CODIGO) FROM '+@DB+'.DBO.SINCRONISMO')

    SELECT @TESTE

    I get this message:

    Msg 8114, Level 16, State 5, Line 8

    Error converting data type varchar to bigint.

    Can someone help, please.

    Thank you

    declare @SQLCmd nvarchar(max),

    @SQLParm nvarchar(max),

    @TESTE bigint,

    @DB nvarchar(128);

    SET @DB = N'SGCTCENTRAL';

    set @SQLCmd = N'SELECT @TESTOUT = MAX(CODIGO) FROM '+@DB+'.DBO.SINCRONISMO');

    set @SQLParm = N'@TESTOUT bigint';

    exec sp_executesql @SQLCmd, @SQLParm, N'@TESTOUT = @TESTE OUTPUT';

    select @TESTE

    Not sure if I did all of that correctly as I did it from memory and I have not tested in my sandbox database. At least it gives you an idea of how to proceed if it works.