Dynamic Query issue

  • Dear All,

    Kindly assist


    DECLARE @query NVARCHAR(MAX);
    SET @query = N'DECLARE @specsAndModel TABLE ( specName VARCHAR(50))'
    SET @Query = @Query + N' INSERT INTO @specsAndModel VALUES('' 1 + 1''); SELECT specName FROM @specsAndModel'
    EXEC (@query);

    The code above returns '1 + 1' and I want it to return 2 instead.

    Thanks.

  • This?

    DECLARE @query NVARCHAR(MAX);

    SET @query = N'DECLARE @specsAndModel TABLE ( specName VARCHAR(50))';
    SET @query += N' INSERT INTO @specsAndModel(specName) select 1 + 1; SELECT specName FROM @specsAndModel';

    EXEC (@query);

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Olalekan Adewale - Thursday, November 1, 2018 11:12 AM

    Dear All,

    Kindly assist


    DECLARE @query NVARCHAR(MAX);
    SET @query = N'DECLARE @specsAndModel TABLE ( specName VARCHAR(50))'
    SET @Query = @Query + N' INSERT INTO @specsAndModel VALUES('' 1 + 1''); SELECT specName FROM @specsAndModel'
    EXEC (@query);

    The code above returns '1 + 1' and I want it to return 2 instead.

    Thanks.


    DECLARE @query NVARCHAR(MAX);
    SET @query = N'DECLARE @specsAndModel TABLE ( specName VARCHAR(50))'
    SET @Query = @Query + N' INSERT INTO @specsAndModel VALUES( 1 + 1); SELECT specName FROM @specsAndModel'
    EXEC (@query);

  • Thanks, am very greatfful.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply