cancel
Showing results for 
Search instead for 
Did you mean: 

Newid() function

SOLVED
New 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 (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"]+"')";

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Newid() function

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"]+"','"+Project["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"] );

 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

4 REPLIES 4
Valued Contributor

Re: Newid() function

before running queries first you have to connect to data base.

There are several way to connect ..I use ADO components.

You can refer  this 

 

beware you have to provide correct connection string.

You can build connection string as mentioned hear

Community Hero

Re: Newid() function

Curiosity has me wondering... where are you getting the function newid () from? Is this from an article online, code already present in your project, something you have from a different tool? The context might be helpful in getting a good solution for you

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Community Hero

Re: Newid() function

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"]+"','"+Project["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"] );

 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

New Contributor

Re: Newid() function

Thank you very much Alex!  Worked perfectly and I also implemented aqString.Format() for readability.  Thanks again!

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors