30.06.2013 Views

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 7-3: The New Cliptext Library window.<br />

215<br />

Chapter 7: Maintaining a Code Library<br />

This will create a new entry on the cliptext dropdown menu, called Transact <strong>SQL</strong><br />

Clips. Click on it and you'll see that the list of selections is empty, but we can now start<br />

adding useful snippets of code that are likely to be needed in numerous places within<br />

your development project. One such example, shown in Listing 7-8, is the classic table<br />

of numbers, or tally table. It's used in all sorts of ways to manipulate data in an efficient<br />

manner within T-<strong>SQL</strong>. Usually, it's a better design to simply create a physical tally table,<br />

but that's not always possible, so this small, temporary tally table may still come in handy.<br />

SELECT TOP 10000<br />

IDENTITY( INT,1,1 ) AS n<br />

INTO #Nums<br />

FROM master.dbo.syscolumns sc1<br />

CROSS JOIN master.dbo.syscolumns sc2 ;<br />

Listing 7-8: A simple tally table.<br />

To get this code snippet into our Transact <strong>SQL</strong> Clips library, return to the library, rightclick<br />

inside the empty space and select Add from the menu to open the Add Cliptext<br />

Item window. Then simply add a meaningful title (e.g. "Tally Table") and then type or<br />

copy Listing 7-8 into the Text body box. Once you've clicked the OK button, the snippet<br />

will be saved to your cliptext library and available for use the next time you're working<br />

on a script in EditPlus. You can drag and drop the entries from the cliptext library into a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!