Merge Table Row Values to Header of Another Table Table 1

id   |  Field           | Values        
----------------------------------------
1    | 'Field01'        |Name           
2    | 'Field02'        |Age  
3    | 'Field03'        |Gender  
4    | 'Field04'        |Qualification




Table 2

id   |  Field01  | Field02 |Field03 |Field04
----------------------------------------
1    | Ajay      |18       |Male    |Bsc

2    | Arun      |19       |Male    |BA  
3    | Aruna     |18       |Female  |Bsc




The OutPut Format is:

id   |  Name     | Age     |Gender  |Qualification
----------------------------------------
1    | Ajay      |18       |Male    |Bsc

2    | Arun      |19       |Male    |BA  
3    | Aruna     |18       |Female  |Bsc
Check this where I answered a similar question on Stack Overflow.

You can do it with dynamic sql:

DECLARE @fieldName varchar(32), @title varchar(32)
DECLARE @sql_cmd varchar(512)
SET @sql_cmd='SELECT id, '

DECLARE sql_cursor CURSOR FOR
SELECT Field, Values FROM table1 ORDER BY id

OPEN sql_cursor

FETCH NEXT FROM sql_cursor INTO @fieldName, @Title

WHILE (@@FETCH_STATUS = 0)
BEGIN
    SET @sql_cmd = @sql_cmd + @fieldName + ' AS ' + @Title + ', '

    FETCH NEXT FROM sql_cursor
    INTO @fieldName, @Title
END;

CLOSE sql_cursor
DEALLOCATE sql_cursor

SET @sql_cmd = SUBSTRING(@sql_cmd,0,LEN(@sql_cmd)-2) + ' FROM table2'
EXEC(@sql_cmd)