# How to integrate a few screens (with db's) into another proj

**URL:** <https://forum.inductiveautomation.com/t/how-to-integrate-a-few-screens-with-dbs-into-another-proj/4389>\
**Category:** Ignition\
**Created:** [May 1, 2012, 3:33pm UTC](https://forum.inductiveautomation.com/t/how-to-integrate-a-few-screens-with-dbs-into-another-proj/4389 "2012-05-01T15:33:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamabelew](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@adamabelew](https://forum.inductiveautomation.com/u/adamabelew)\
**Post date:** [May 1, 2012, 3:33pm UTC](https://forum.inductiveautomation.com/t/how-to-integrate-a-few-screens-with-dbs-into-another-proj/4389/1 "2012-05-01T15:33:15Z")

</div>

Hello All,

I have a project with 2 widows that I would like to import into another project (maybe to have available for others). Is there a way to “package” these windows for easy integration into other projects? Also, these windows require (2) database tables to function. Is there a way to have this package automatically create the necessary tables?

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [May 1, 2012, 4:41pm UTC](https://forum.inductiveautomation.com/t/how-to-integrate-a-few-screens-with-dbs-into-another-proj/4389/2 "2012-05-01T16:41:53Z")

</div>

It might be useful to build some scripts that create your tables and any default information in a window that is only accessible through the designer.

For example:

```auto
CREATE TABLE customer
(First_Name char(50),
Last_Name char(50));

INSERT INTO customer (First_Name, Last_Name) VALUES 
('John', 'Smith'), 
('Gordon', 'Freeman'), 
('John', 'Nash');
```

Make a button that runs a script that executes your SQL statements from above and stick it on a window only available through the designer. When you have a new a project import the window, switch the designer to run mode, hit the button, and you’re done.

---

<div class="post-metadata">

**Author:** ![adamabelew](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@adamabelew](https://forum.inductiveautomation.com/u/adamabelew)\
**Post date:** [May 1, 2012, 5:17pm UTC](https://forum.inductiveautomation.com/t/how-to-integrate-a-few-screens-with-dbs-into-another-proj/4389/3 "2012-05-01T17:17:31Z")

</div>

hmmm, That got me thinking. I could create a transaction group that creates the table(s) if it doesn’t exist. I have done that previously in an older project using FSQL.

Thanks for the input.

---

<div class="post-metadata">

**Author:** ![adamabelew](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@adamabelew](https://forum.inductiveautomation.com/u/adamabelew)\
**Post date:** [May 3, 2012, 3:20pm UTC](https://forum.inductiveautomation.com/t/how-to-integrate-a-few-screens-with-dbs-into-another-proj/4389/4 "2012-05-03T15:20:15Z")

</div>

I decided to do as suggested and have created a SQL statement to see if table exsists, and if it does not, it will be created. I have tested the script in the SQL management studio and it works fine. However, I cannot get it to run with a pushbutton event handler script.

This is the script that I have that works in the SQL management studio:

```auto
system.db.runQuery(IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TABLENAME]') AND type in (N'U')) CREATE TABLE [dbo].[TABLENAME]([Idx] [int] IDENTITY(1,1) NOT NULL,[COL1] [varchar](100) NULL,[UserID] [varchar](50) NULL,[COL2] [varchar](50) NULL,[COL3] [int] NULL,[TABLENAME_ndx] [int] NULL)
```

Am I missing something obvious?

Thanks

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [May 3, 2012, 3:49pm UTC](https://forum.inductiveautomation.com/t/how-to-integrate-a-few-screens-with-dbs-into-another-proj/4389/5 "2012-05-03T15:49:07Z")

</div>

I think you should run that query in a runPrepUpdate instead of runQuery. runQuery expects a query that returns results. Try this:`system.db.runPrepUpdate("IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TABLENAME]') AND type in (N'U')) CREATE TABLE [dbo].[TABLENAME]([Idx] [int] IDENTITY(1,1) NOT NULL,[COL1] [varchar](100) NULL,[UserID] [varchar](50) NULL,[COL2] [varchar](50) NULL,[COL3] [int] NULL,[TABLENAME_ndx] [int] NULL", [])`

---

<div class="post-metadata">

**Author:** ![adamabelew](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@adamabelew](https://forum.inductiveautomation.com/u/adamabelew)\
**Post date:** [May 3, 2012, 6:32pm UTC](https://forum.inductiveautomation.com/t/how-to-integrate-a-few-screens-with-dbs-into-another-proj/4389/6 "2012-05-03T18:32:49Z")

</div>

The problem has been resolved. The script is working well.

Thanks…
