Sharing SQL Queries

 

Today I wanted to post a tip on how to share queries.  Often users or the PDOTeam will post a query and we want you to know how to use that in your own project (like the query below).

 

SELECT [Components-Valves].ID_COUNT_, [Components-Valves].DWG_NAME_, [Components-Valves].SIZE_, [Components-Valves].SPEC_, [Components-Valves].CW_RES_01_, [Components-Process Lines].TAG_, [Components-Process Lines].SIZE_ AS [Line Size], IIf([Components-Valves]![SIZE_]=[Line Size],"Y","N") AS [Match]
FROM [Components-Valves] INNER JOIN [Components-Process Lines] ON [Components-Valves].LINE_ID_1_ = [Components-Process Lines].ID_COUNT_;

 

The query above will display a list of the valves and whether or not their size matches the size of the line they are on.  You can quickly see the drawings that have lines you need to fix. 

Below follows the technique for adding the query to your project database.

First copy the text to the clipboard.

clip_image002

Next, in Access start a new query in Design View from the Create Tab.

clip_image004

Close the Show Table dialog, right-click on the header and choose SQL View.

clip_image006

clip_image008

Paste the query.

clip_image010

Now, you can use the query by saving it and switching to Datasheet view.

clip_image012

Don’t forget that Exporting to Excel to produce or sort a query is really easy too.  Just right-click the query from the Navigation pane, highlight export and choose Excel.

clip_image014

I hope you find this useful!