Quantcast
Channel: T-Sql – Developing Matt
Viewing all articles
Browse latest Browse all 20

The Lazy Programmer

$
0
0

There once was a lazy programmer who did nothing but sat around reading the newspaper at work.  Lazy programmer would listen to audio books, surf the web for amazon deals, and watch youtube videos.  Lazy programmer sat around and ate potato chips in between laughing at the jokes he found on forums he constantly monitored about his extravagant online gaming addiction that he sustained at night.  People would walk by and get irritated and complain to their coworkers.  Lots of murmuring about this programmer and the apparent lack of motivation to do the job.  But the boss never did anything, never said anything, never talked to the lazy programmer about this individual’s lack of apparent work ethic.  Everyone wanted the lazy programmers job, but the truth is no one could do the job.  The lazy programmer was worth his weight in gold because if something needed to be done lazy programmer would take care of things quickly and efficiently, because he didn’t like to work. 

Someday we will all be there, but it’s going to take some careful considerations of how to most effectively get things done smarter and more efficiently.  Here is a script that I use for various sundry things to retrieve column names and datatypes out of a table.  For example, if I need to create a procedure that has almost all the parameters in a table I will do something like this to get the declaration section of the procedure

select ‘@’ +  s.name
,datatype  = st.name +  case st.name when ‘varchar’  then ‘(‘ + CAST( s.length as varchar(15)) + ‘)’
when ‘char’  then ‘(‘ + CAST( s.length as varchar(15)) + ‘)’
else ” end
from syscolumns s
join systypes st on s.xtype = st.xtype
where s.id = 1765581328 –-database id

And if I need to build a where clause out of these same parameters I would do something like this (although not an efficient way to do this for a good execution plan)

select ‘and (‘ +  s.name + ‘=@’ + s.name + ‘ or @’ + s.name + ‘ is null )’
from syscolumns s
join systypes st on s.xtype = st.xtype
where s.id = 1765581328



Viewing all articles
Browse latest Browse all 20

Trending Articles