note 60228 added to function.mssql-query

From: Date: Fri, 30 Dec 2005 15:35:09 +0000
Subject: note 60228 added to function.mssql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-100994@lists.php.net to get a copy of this message
It would appear that MSSQL will not let you use fields of the TEXT data type in WHERE clauses. I tried running a simple query to get account data for a particular user based on email address, but the command was not returning any data. I finally realized that this was because the emailaddress column was of the data type TEXT. When I changed the WHERE clause in the query to test against a name, which was of type VARCHAR, the query worked perfectly. I overcame this problem by converting the TEXT field to VARCHAR in the WHERE clause, as noted below: <?php ### Field 'emailaddress' is of data type TEXT in the SQL database # This would not work! $sql = "SELECT * FROM accounts WHERE emailaddress = 'test@test.com'"; # Converting the data type inline solved the problem $sql = "SELECT * FROM accounts WHERE CONVERT( VARCHAR, emailaddress ) = 'test@test.com'"; ?> This seems to have solved my problem, although I am still unsure of the limits (if any) to this solution. ---- Manual Page -- http://www.php.net/manual/en/function.mssql-query.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60228 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60228&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60228&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60228&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60228&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60228&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60228&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60228&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60228&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100994) next »