I, Codemonkey

Codemonkeying Around
posts - 4, comments - 7, trackbacks - 0

My Links

News

Archives

Nested String Statements

Here's a strange one. Last night I had a dream about nested strings. The most obvious use of this would be in a nested SQL statement, so here's a made up on the fly example:

select   phone_number
from Addressbook
where name = (select name from customers where city = 'Atlanta')

But instead of writing that out as a string in my code, I did this crazy thing:

string sQuery = "select name from customers where city = 'Atlanta'";
sQuery = " select   phone_number from Addressbook where name = (" + sQuery + ")";

Mostly, I would never use that. It's far too difficult to go back and read later. However, I got to thinking and it might be interesting to use that with a dynamically created SQL statement. Say I was going to do a phone look up, but I wasn't sure what I was going to do the test against, I could use this little pattern. That way I could do a lookup versus city, zip code, PO numbers, or anything else, and it might actually be easier to read in the future this way than with some kind of nested if statement that creates the SQL through conditional statements.

I'll have to think on this a little more.

Print | posted on Monday, June 25, 2007 8:11 AM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: