By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

Return more than one value(store procedure)

P: 83
can i do like this Return (4),@fieldname
an how to asign value @fieldname with the value of fieldname that use select from table?
Nov 7 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,134
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

Expand|Select|Wrap|Line Numbers
  2. set @fieldname=(select TheField from TheTable)
Of course, the select statement must return 1 record only in the above example.
Nov 12 '08 #2

Expert 100+
P: 1,134
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

Expand|Select|Wrap|Line Numbers
  2. DECLARE @SQLString NVARCHAR(500) --Must be NVARCHAR
  4. set @SQLString='SELECT ' + @fieldname + '  FROM YourTable'
  6. EXEC sp_executesql @SQLString
Nov 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.