georgiadonut
8 years agoNew Contributor
Newid() function
Hello All -- I am very new to TestComplete and am trying to do a database insert using newid() but keeping getting the error "NEWID" is not defined. I've tried various different formatting (sin...
- 8 years ago
Hi,
Your code tries to call newid() function, get its result and use this result as a value in the query. As newid() is an internal SQL function, TestComplete cannot call it and reports this as an error.
You must include the call to the newid() function into your SQL statement so that it is SQL engine that will call it in its context and use the returned result. Something like this:
query = "INSERT INTO "+ProjectSuite["Variables"]["PrimaryDB"]+".[dbo].[
Workstations](ID,[LocID],[Name])VALUES(newid(),"+Project["Variables"]["PrimaryLocID"]+"','"+P roject["Variables"]["Workstation"]+"')"; P.S. For better visual clarity I prefer to use the aqString.Format() function. The above line in this case looks like this:
query = aqString.Format("INSERT INTO %s.[dbo].[Workstations] (ID, [LocID], [Name]) VALUES (newid(), %s, %s)", ProjectSuite["Variables"]["PrimaryDB"], Project["Variables"]["PrimaryLocID"], Project["Variables"]["Workstation"] );