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 (single quotes, double quotes, etc) as well as creating a variable to store the uniqueidentifier but always get same error.
Is there a special library I need to include to use this SQL function or special formating?
Thank you in advance for your help.
query = "INSERT INTO "+ProjectSuite["Variables"]["PrimaryDB"]+".[dbo].[Workstations](ID,[LocID],[Name])VALUES('"+newid()+"','"+Project["Variables"]["PrimaryLocID"]+"','"+Project["Variables"]["Workstation"]+"')";
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"] );