The below Stored Procedure do What you need
CREATE PROCEDURE [dbo].[Rotat]
-- Add the parameters for the stored procedure here
@Where nvarchar(max),
@tableName nvarchar(max)
AS
BEGIN
Declare @SqlQuery nvarchar(max),@ColumnName nvarchar(255)
DECLARE @TempTable TABLE
(
ID int IDENTITY(1,1) ,
ColumnName nvarchar(255),
ColumnValue ntext
)
INSERT INTO @TempTable (ColumnName)
SELECT column_name
FROM information_schema.columns
WHERE table_name = @tableName
Declare @index int
Set @index = 1;
Declare @Count int
Select @Count = Count(ID) from @TempTable
declare @columnValue nvarchar(255)
declare @paraDef nvarchar(max)
declare @string nvarchar(max)
WHILE @index <= @Count
BEGIN
Select @ColumnName = ColumnName from @TempTable where id = @index
set @string ='select @ret= cast('+ @ColumnName + ' AS nvarchar(255) )
from '+@tableName+' WHERE ' + @Where
set @paraDef=N'@ret nvarchar(255) output'
EXECUTE sp_executesql @string, @paraDef,@ret=@ColumnValue output
UPDATE @TempTable
SET ColumnValue = @columnValue
WHERE ID =@index
Set @index = @index + 1
END
Select * from @TempTable
END
Just call it an pass table name and your condition that will return one row for example
EXEC [dbo].[Rotat]
@Where = 'UserID = 123456',
@tableName = 'Users'