Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Server problem
Message
 
À
09/02/2007 12:27:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01194131
Message ID:
01194136
Vues:
12
>I am having a problem with a select from SQL Server. My code is as follows:
>
>*lcPermId = alltrim(companyinfo.PermID) && removed for testing
>lcPermID = '1178072'
>lnProgramYear = companyinfo.yearproduced
>lcRawTable = addbs(fileloc) + "surveys\RawData" + transform(lnProgramYear) + '.dbf'
>
>lcConnectionString = "DRIVER=SQL Server;SERVER=PAG-SQLSERVER;" + ;
>		"UID=DonF;APP=Microsoft Visual FoxPro;" + ;
>		"WSID=TPD284;DATABASE=TRPSurvey;Trusted_Connection=Yes"
>lnHandle = sqlstringconnect(m.lcConnectionString)
>lcSQL = "select * " + ;
>	"from TRPSurvey" + "..exported " + ;
>	"where lcPermID = alltrim(PermID)"
>
>sqlexec(m.lnHandle,lcSQL,"crsImport")
>sqldisconnect(m.lnHandle)
>
>
>The problem is that the select does not return any records when the WHERE clause is used even though I know there are records that meet the criteria. If I drop the WHERE clause it works fine and returns all of the records. Does SQL Server not support WHERE?
>
>- Don

Don, SQL Server has no such function like ALLTRIM(). Better make PermId to be varchar not CHAR. Also SQL Server doesn't know the value of lcPermID. YTou must pass that value as parameter or direclty use its value:
** 1. use lcPermID as parameter
lcSQL = "select * " + ;
	"from TRPSurvey" + "..exported " + ;
	"where PermId = ?m.lcPermID"


** 2. Direct use of lcPermID
lcSQL = "select * " + ;
	"from TRPSurvey" + "..exported " + ;
	"where PermId = '"+m.lcPermID+[']

*** SQLEXEC()
sqlexec(m.lnHandle,lcSQL,"crsImport")
Also ALWAYS check what SQLEXEC returns. That way you will have information WHY that statement is not run:
IF sqlexec(m.lnHandle,lcSQL,"crsImport") < 0
   AERROR(laError)
   MessageBox(laError[1,2])
ENDIF
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform