Hi - Is it possible to use a table variable with sqlsrv_query? Below is some sample code that isn't working...nothing is displayed on the screen when the function is called:
function fnEntryForm($dbc) { $sql = " declare @t as table(Object nvarchar(50), ColumnName nvarchar(50), UIName nvarchar(50), TextBoxWidth int, TextBoxWidthUOM nvarchar(2)); --UIName = user interface name insert into @t values ('Users', 'UserID', 'User ID', 3, 'em'), ('Users', 'StreetAddress', 'Address', 10, 'em'), ('Users', 'City', 'City', 8, 'em'), ('Users', 'State', 'State', 2, 'em'), ('Users', 'Zip', 'Zip Code', 3, 'em'); --select * from @t; select t.*, c.* from sys.columns c inner join @t t on c.object_id = object_id(t.Object) and c.Name = t.ColumnName; "; $query = sqlsrv_query($dbc, $sql); if($query === false): exit("query failed"); else: // echo "<ol>\n"; while ($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)): // echo '<li>' . $row['Name'] . '</li>' . "\n"; echo '<pre>' . print_r($row) . '<pre>'; endwhile; // echo "</ol>\n"; endif; //free up query resources sqlsrv_free_stmt($query); }
When a simple query replaces what's in $sql shown above like this:
$sql = " select Name from sys.columns where object_id = object_id('Users');";
then it displays the data fine. This leads me to believe there is a problem with using a table variable. Is there a way to get it to work?
Secondarily, is it common practice to store user interface data, such as that shown in the table variable, in the database so HTML elements can be created using just a few lines of code or do most developers hand code each HTML element?