Hi,I have a sproc that has been coded for me but I am having a problem. The stored procedure runs fine within MS SQL Server Management studio but when I run it through PHP it fails.This is the PHP code used to run it:$myServer = "xxxx";$myUser = "xxxx";$myPass = "xxxx";$myDB = "xxxx";//connection to the database$dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");//select a database to work with$selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB");$query="EXEC spAllFixtures"; $result=mssql_query($query);while($row=mssql_fetch_array($result)){ echo $row['OrganisationID']."<br/>"; }
And this is the stored procedure:CREATE Procedure spAllFixturesAs set nocount on DECLARE @WhatClub int DECLARE @NumFound int DECLARE @SQLcommand varchar(1024) DECLARE @NoFixtureList varchar(1024) DECLARE cur_find_fixtures CURSOR LOCAL FAST_FORWARD FOR SELECT ClubID FROM tblClubs OPEN cur_find_fixtures FETCH FROM cur_find_fixtures INTO @WhatClub-- WHILE (@@FETCH_STATUS <> -1) -- BEGIN -- EXEC @NumFound =dbo.spNumAvailableFixtures @WhatClub IF @NumFound = 0 SET @NoFixtureList = COALESCE(@NoFixtureList + ',', '') + CONVERT(varchar(12), @WhatClub) -- FETCH FROM cur_find_fixtures INTO @WhatClub-- END CLOSE cur_find_fixtures DEALLOCATE cur_find_fixtures SET @SQLcommand = 'SELECT ClubID, Replace(OrganisationID,'''''''','''') AS OrgName FROM tblClubs ' IF @NoFixtureList <> '' SET @SQLcommand = @SQLcommand + 'WHERE ClubID NOT IN (' + @NoFixtureList + ')' SET @SQLcommand = @SQLcommand + ' ORDER BY ClubID;' EXECUTE(@SQLcommand) return
The PHP spits out this error:Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near ','. (severity 15) in c:\Inetpub\wwwroot\xxx\test.php on line 21. This line refers to the $result=mssql_query($query); line within the PHP.Has anyone seen this before?Thanksp.s. I realise that this is an SQL forum and not a PHP forum but I was kinda hoping someone from the SQL community may have seen this problem before.