1. Get column name in SQL Server
For example:
SELECT table_name=sysobjects.name,
column_name=syscolumns.name,
datatype=systypes.name,
length=syscolumns.length
FROM sysobjects
2. Example to execute the query in PHP
$firstname="fred";
$lastname="fox";
$query = sprintf("SELECT firstname, lastname FROM friends WHERE firstname="%s" AND lastname="%s"",
mysql_real_escape_string($firstname),
mysql_real_escape_string($lastname));
$result = mysql_query($query);
solved How to get a column name in SQL Server? [closed]