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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert the values of all the fields into variable

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

@KeyField

I need to storage into a variable the values of ALL THE FIELDS separeted by |

For example if my table is Customers

CustomerID CustomerName City

111 Adventure Boston

222 Pubs NY

And I execute EXEC mysp 'Customers',111

I need a return value like this

@ReturnValue = 111|Adventure|Boston

I create something like this

CREATE PROCEDURE my sp

@table varchar

@key numeric

AS

@field varchar(40),

@object int


Select @object = object_id from systables where name =@table

--The instructions to create a cursor

WHILE (@@FETCH_STATUS = 0 )


Select @object = name from sys.columns where object_id = @object




--The instructions to close and deallocate the cursor

I have alredy to save the value using the EXEC command but is not working; something like

@String = Select @object from @table where CustomerID = @keyValue


Can 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]
Go to Top of Page
   

- Advertisement -