Return more than one value(store procedure)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MATTXtwo
    New Member
    • Sep 2006
    • 83

    Return more than one value(store procedure)

    can i do like this Return (4),@fieldname
    an how to asign value @fieldname with the value of fieldname that use select from table?
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    I don't follow what you mean by

    Return (4),@fieldname
    Please explain more fully?

    as to assigning @fieldname to the result of a select

    [code=sql]

    set @fieldname=(sel ect TheField from TheTable)

    [/code]

    Of course, the select statement must return 1 record only in the above example.

    Comment

    • Delerna
      Recognized Expert Top Contributor
      • Jan 2008
      • 1134

      #3
      If you mean you want to return the value of a field that is identified by @fieldname, then you will need to use dynamic query for that.

      something like

      [code=sql]

      DECLARE @SQLString NVARCHAR(500) --Must be NVARCHAR

      set @SQLString='SEL ECT ' + @fieldname + ' FROM YourTable'

      EXEC sp_executesql @SQLString

      [/code]

      Comment

      Working...