Developing Matt

My Technical Journal

Table Variables

leave a comment »

Use a variable
table you see
Make the first column
an identity
Be sure you add
and increment your seed
and loop through rows
with fun and ease

rowcount. identity
intertwined brothers
spits back your data
like an angry mother
It’s quick and clean
An unstored table
Your dba smiles
when no temporary tables.

Save your i/o
Use only RAM
disappears quick
like an angry fan
like a mouthwash junkie
it’s gone with the scope
a variable religion
full of hope.


–table variable example

–create your table variable

declare @tbl table (id int identity (1,1),strItem varchar(200), strBusiness varchar(120))

insert into  @tbl (strbusiness, stritem)

      select business, appsetting from passthru

      where business  <> ‘my business’


declare @count int

set @count =1

while @count <= (select max(id) from @tbl)


   –do your looping stuff

      select strBusiness from @tbl where id = @count

      set @count = @count +1




Written by matt

April 7, 2008 at 3:44 pm

Posted in poetry, T-Sql

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: