Home Forums SQL Server 7,2000 T-SQL create single quotes around @variable RE: create single quotes around @variable

  • Just because this thread was revived after 9 years, I'd like to make a few suggestions.

    Use parametrized dynamic sql and always define precision and scale for your types. In 2000, there was the restriction of 4000 characters, in 2005 the restriction basically disappears with NVARCHAR(MAX).

    DECLARE @sql NVARCHAR(MAX);

    DECLARE @p_number NUMERIC(18, 0);

    SET @p_number = 134070;

    SET @sql = 'SELECT * FROM M_Driemnd(@p_number)';

    EXEC sp_executesql @sql, N'@p_number NUMERIC(18, 0)', @p_number;

    There's also no case on making this code dynamic, but a more complex process might be worth of it. This should only be treated as an example.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2