Jump to content

Ambiguous Column


ShadowMage

Recommended Posts

I have the following query:

$sql = "SELECT UserFile.DcdUserID, UserComp.PlantList FROM UserFile INNER JOIN UserComp ON UserFile.DcdUserID = UserComp.DcdUserID";

but it's giving me the following error:

PHP Warning:  odbc_fetch_array(): SQL error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Ambiguous column name 'DcdUserID'., SQL state 37000 in SQLGetData 

If I adjust the query with an alias on 'DcdUserID' as follows:

$sql = "SELECT UserFile.DcdUserID AS 'UserID', UserComp.PlantList FROM UserFile INNER JOIN UserComp ON UserFile.DcdUserID = UserComp.DcdUserID";

then it tells me that 'UserID' is an invalid column name.  Any ideas what's going on here?  I can't see any issues with the SQL and in fact both queries run in a standalone querying tool we use (ODBC Test Utility) without issue.

Link to comment
Share on other sites

Shoot.  Forgot I posted here.  It ended up being an issue with Epicor (the DB I'm connecting to).  Turns out that UserComp.PlantList is a varchar(1000) field and any time we try to pull out a 1000 character field from Epicor in PHP, we have to use CAST(fieldname AS varchar(1000)) or we get funky, completely unrelated, inaccurate error messages.  Like this one.

Anyway, thanks for looking, Ingolme.  Much appreciated.

On a completely unrelated sidenote: What happened to this place?  This used to be a fairly active community, but now it's almost like a ghost town...😕

Link to comment
Share on other sites

The internet has changed, forums are a mostly forgotten medium. People get their information from social media sites and Discord channels. Speaking of that, W3Schools has a Discord channel link under the "Services" menu of their website. The link to the forums is very tiny in the website footer.

Link to comment
Share on other sites

That's unfortunate.  And also probably true...  I much prefer forums for this type of thing and I actually kind of despise the social media type stuff.  I have a strange urge to make a comment about whipper-snappers and ... lawns ... and? 🤔

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...