Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jesanlop
Starting Member
1 Post |
Posted - 2014-08-07 : 02:00:41
|
Hi Experts,I really would appreciate your help for the following problem; I need to créate a stored procedured, this procedure will receive two parameters:@TableName@KeyFieldI need to storage into a variable the values of ALL THE FIELDS separeted by |For example if my table is CustomersCustomerID CustomerName City111 Adventure Boston222 Pubs NYAnd I execute EXEC mysp 'Customers',111I need a return value like this@ReturnValue = 111|Adventure|BostonI create something like thisCREATE PROCEDURE my sp@table varchar@key numericAS@field varchar(40),@object intSelect @object = object_id from systables where name =@table--The instructions to create a cursorWHILE (@@FETCH_STATUS = 0 )Select @object = name from sys.columns where object_id = @object--The instructions to close and deallocate the cursorI have alredy to save the value using the EXEC command but is not working; something like@String = Select @object from @table where CustomerID = @keyValueCan you please help me,Thanks  I want to learn |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2014-08-07 : 07:21:27
|
Have a look here (second answer): [url]http://social.msdn.microsoft.com/forums/sqlserver/en-US/61685438-7969-4a5e-9626-e8a4af54eb08/concatenate-all-the-column-values-in-one-row[/url] |
 |
|
|
|
|