How get value from function using EXECUTE sp_executesql RRS feed

  • General discussion

  • I've following Sql Query and I want it in a function

    DECLARE @ParmDefinition NVARCHAR(500);
    DECLARE @TableName VARCHAR(100);
    DECLARE @SelectField varchar(100);
    DECLARE @WhereField varchar(100);
    DECLARE @WhereFieldValue varchar(100);

    SET @TableName ='dbo.Customer';
    SET @SelectField =' CompanyName ';
    SET @WhereField =' CustomerId ';
    SET @WhereFieldValue ='1';

    /* Build the SQL string one time. */
    SET @SQLString =
         N'SELECT '+@SelectField+' FROM '+@TableName+' WHERE '+@WhereField+' = @pWhereFieldValue';

    /* Specify the parameter format one time. */
    SET @ParmDefinition = N'@pWhereFieldValue varchar(100)';

    /* Execute the string with the parameter value. */
    EXECUTE sp_executesql @SQLString, @ParmDefinition,
                          @pWhereFieldValue = @WhereFieldValue;

    Please reply me with solution.

    Thanks in advance

    Gurpreet Deol

    Monday, September 24, 2012 3:17 PM

All replies

  • Hi Gurpreet Deol,

    This forum is dedicated to Microsoft Project Server. Please repost your question on appropriate forum.

    Hrishi Deshpande – Senior Consultant DeltaBahn
    Blog | < | LinkedIn

    Please click Mark As Answer; if a post solves your problem or Vote As Helpful; if a post has been useful to you.This can be beneficial to other community members reading the thread.

    Monday, September 24, 2012 4:17 PM