Home Forums SQL Server 7,2000 T-SQL Dynamic SQL issues with passing variables in stored procedure RE: Dynamic SQL issues with passing variables in stored procedure

  • Guys, I tried both;

    First results of print @SQL;

    INSERT INTO dbo.ImportError

    (DataElementID, CenterCode, ValueType, ValueDate, [Value], ImportDate, BatchID, ErrorReason)

    SELECT DataElementID, CenterCode, ValueType, ValueDate, [Value], GetDate(), '463', 'DataElementID too much characters (>3)'

    FROM dbo.ImportAccess

    WHERE LEN(DataElementID) > 3

    Looks promising, but the procedure generates this error;

    Server: Msg 170, Level 15, State 1, Line 3

    [Microsoft][ODBC SQL Server Driver][SQL Server]Line 3: Incorrect syntax near 'LEN(DataElementID) > 3'.

    Failed to get the call stack!

    @RETURN_VALUE = N/A

    The second code by Ronald gives the following for @SQL;

    INSERT INTO dbo.ImportError

    (DataElementID, CenterCode, ValueType, ValueDate, [Value], ImportDate, BatchID, ErrorReason)

    SELECT DataElementID, CenterCode, ValueType, ValueDate, [Value], GetDate(), '463', 'DataElementID too much characters (>3)'

    FROM dbo.ImportAccess

    WHERE 'LEN(DataElementID) > 3'

    Last line won't work, but after removing 4 quotes from the @WhereStatement variable it produces the same error as the first piece of codes does. (incorrect syntax)