Simple Example of Using the World's Simplest Code Generator....
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Simple Example of Using the World's Simplest Code Generator....

The World's Simplest Code Generator can be used for millions of little tasks in any programmer's daily life. Here is one simple example.

Just say you Urgently need to know the number of rows in EVERY user table in your database...

In sql analyzer, run this:

select name from sysobjects where type = 'u'

This returns a list of all the user tables...

Orders
Products
Order Details
CustomerCustomerDemo
CustomerDemographics
Region
Territories
EmployeeTerritories
Employees
Categories
Customers
Shippers
Suppliers

Now paste that data into the first box in 'The World's Simplest Code Generator'

And paste this 'Pattern' into the second box:

SELECT
       '$1' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [$1]
UNION

Click [calculate] and 'Voila!'

You have this script:

SELECT
       'Orders' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Orders]
UNION
SELECT
       'Products' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Products]
UNION
SELECT
       'Order Details' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Order Details]
UNION
SELECT
       'CustomerCustomerDemo' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [CustomerCustomerDemo]
UNION
SELECT
       'CustomerDemographics' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [CustomerDemographics]
UNION
SELECT
       'Region' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Region]
UNION
SELECT
       'Territories' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Territories]
UNION
SELECT
       'EmployeeTerritories' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [EmployeeTerritories]
UNION
SELECT
       'Employees' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Employees]
UNION
SELECT
       'Categories' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Categories]
UNION
SELECT
       'Customers' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Customers]
UNION
SELECT
       'Shippers' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Shippers]
UNION
SELECT
       'Suppliers' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Suppliers]
UNION

(remove the word 'UNION' from the very end, before you use it...)

Execute the script in SQL Query Analyser... and here's the result:

a grid showing the sizes of each column in the database

Okay -- now any DBA could've solved that problem in a few other ways, that show off all their fancy-schmancy dba skills and justify all the time they spend reading big thick books about system stored procedure, when they should be down at the local bar trying to meet a life partner.

But the power of 'The World's Simplest Code Generator'is that you can use it to multiply the little bit of knowledge you do have, and get results on a broad number of programming problems in a big big hurry.

Here's some suggested uses:

  • XML: turn a CSV list into a scrap of XML, great for test purposes. For example, testing an RSS reader!
  • HTML: need to craft a HTML table by hand, or to write a html list by hand?
  • C# property getters and setters: Got a list of variable names that you need setters and getters for? (examples provided in the comments here
  • VB.Net property getters and setters: Got a list of variable names that you need setters and getters for? (examples provided in the comments here
  • .Net: repetitive code for validation, or perhaps serialization; need .net wrappers for interop purposes?
  • SQL: Stored procedures to write? Insert/Update statements, union statements, backup scripts...
  • PHP: I don't write PHP myself, but I know this tool could come in handy there
  • Batch files:Some times an administration task will require the construction of a big verbose chain of commands like this: "if not exist x md x"... bring on the WSCG....
  • Any other language you like

This, however, can leave you with so much spare time that they inscribe your name on a plaque on a bar stool down at the local pub. So use this tool wisely and in moderation.





'garcia' on Tue, 17 May 2005 00:41:26 GMT, sez:

Technique to get the columns of a table ('Customers' in this case)

SELECT
obj.name AS 'tableName',
col.name AS 'ColName'
FROM
syscolumns col
INNER JOIN
sysobjects obj
ON col.id = obj.id
WHERE obj.type = 'u'
AND obj.name = 'Customers'



'Oliver Townshend' on Thu, 30 Jun 2005 01:10:39 GMT, sez:

I'd use UNION ALL rather than UNION, or even go. It's faster, and it will cope with two tables with the same name (but different owners).



'sg' on Thu, 30 Jun 2005 07:01:35 GMT, sez:

Thanks Oliver




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Aim for constructiveness. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Also, I get particularly nasty on comment spam. It's not worth even trying to post comment spam here -- your html is escaped, and your links are given a rel='nofollow'. By attempting to post a comment, you understand that if the comment is considered spam, at my absolute discretion, your IP address may be used as the target of a prolonged distributed denial of service attack. Your electricity might suddenly stop working. Your car tyres will go mysteriously flat. You will suffer permanent hairloss. Your dreams will be filled with terrifying monsters. And in any case I reserve the right to record and publish your IP address.

 

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

Use it for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. Use it right now! Go on! Hurry! Don't walk, run!

 

Articles

Just Wally Just Wally
The Correct Order for a First Time Viewing of The Lord Of The Rings The Correct Order for a First Time Viewing of The Lord Of The Rings
A new era for Android. A new era for Android.
Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes. Got CSV in your javascript? Use agnes.

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal
NimbleText -- World's Simplest Code Generator NimbleText: Code Generator, Text Manipulator, Data Extractor

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
Thomas White
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2003 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2003 .: privacy