Dynamic stored procedure question.....?

Results 1 to 2 of 2

Thread: Dynamic stored procedure question.....?

  1. #1
    Charlie Pyne Guest

    Default Dynamic stored procedure question.....?

    When using sp_executesql are you allowed to use a parameter that represents a column name you want to search???<BR><BR><BR>Heres a simplified version of what I&#039m trying to do....<BR><BR>CREATE PROCEDURE splookup_order <BR>AS<BR><BR>BEGIN<BR>DECLARE @SQLString NVARCHAR(1000)<BR>DECLARE @ParmDefinition NVARCHAR(500)<BR><BR>SET @sqlstring = N&#039<BR>SELECT * FROM orders AS o<BR>WHERE @column_name = @search_for&#039<BR><BR>SET @parmdefinition = N&#039@column_name varchar(25), @search_for INT&#039<BR><BR>EXECUTE sp_executesql @SQLString, @ParmDefinition, @column_name = &#039order_number&#039, @search_for = 234<BR><BR>END<BR>GO<BR><BR><BR>This example should execute...<BR><BR>SELECT * FROM orders<BR>WHERE order_number = 234<BR><BR>I&#039ve got this to work if I just do the 234 as a parameter..<BR><BR>Passing the column name gives me...<BR><BR>Syntax error converting the varchar value &#039order_number&#039 to a column of data type int.

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Curiosity aroused

    what is the N for in your sql the set @sqlstring = N&#039<BR> <BR><BR>you seem to be using it everywhere you are assigning a value to something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts