A weird casestudy in technical research
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

A weird casestudy in technical research

I used SQL profiler to grab the SQL that a crystal report generated.

Here's a snippet:

AND "Customer"."OrderDate"<{ts '2007-08-17 00:00:01'})

The curly brackets and the 'ts' looked strange to me. Not something I'd used before.

I wasn't sure what sort of thing 'ts' was. I googled it -- and found nothing. I checked SQL Server books on line, but no luck there either. Squiggly brackets and 'ts' are, by their nature, very hard to search for.

So I tried some variations to see what happened:

Select {ts '2007-08-17 00:00:01'} -- returns a date
Select {'2007-08-17 00:00:01'} -- fails (Syntax error or access violation)
Select ts '2007-08-17 00:00:01' --fails (Invalid column name 'ts')
Select ts('2007-08-17 00:00:01') --fails ('ts' is not a recognized function name)
select {ts '1'} -- fails (Syntax error converting datetime from character string)
Select {as '2007-08-17 00:00:01'} -- fails (Syntax error or access violation)

I figured it's some kind of special built in thing. And if this exists, there must be other special built in things I don't know about.

I wrote a short powershell program that generates all the combinations of two letters "aa, ab, ac..." right up to "zz". And then (using WSCG) I generated a monster T-SQL script of this form:

select 'aa'
go
Select {aa 5}
go
select 'ab'
go
Select {ab 5}
go
--(and so on up to 'zz')

Now I ran that script to see if any other two letter combinations stood out, and returned different error messages to the rest.

It turned out there were three such pairs of letters that produced a different error result to the rest:

  1. fn
  2. oj
  3. ts

Now googling those three all together was enough to get me a result, and thus find the meaning and documentation on 'ts'!

'ts' -- incase you didn't guess -- is short for 'time stamp'. These squiggly bracket sequences come to us from the world of ODBC, and crystal presumably uses them because it is trying to be platform (and region) agnostic.

The following is from "Writing International Transact-SQL Statements":

ADO, OLE DB, and ODBC applications should use the ODBC timestamp, date, and time escape clauses of:
{ ts 'yyyy-mm-dd hh:mm:ss[.fff] '} such as: { ts '1998-09-24 10:02:20' }
{ d 'yyyy-mm-dd'} such as: { d '1998-09-24' }
{ t 'hh:mm:ss'} such as: { t '10:02:20'}

And this from google groups...:

ODBC provides a ODBC syntax for dates ( { d 'yyyy-mm-dd'} ), timestamps { ts '...'}), functions ( { fn RIGHT() } ... ) and even outer joins ( { oj .... }). So, if you write using ODBC syntax :

    SELECT * FROM MyTable WHERE MyField = { d '2000-12-31' } 

each ODBC driver translates it into native syntax of its underlying engine before sending the statement. You can see the documentation of ODBC syntax in the Appendixes of ODBC Programmer's Reference (MDAC documentation).





'Mike Gunderloy' on Tue, 21 Aug 2007 00:38:26 GMT, sez:

Or you could Google

"sql server" date "ts"


I know, not nearly as much fun as writing PowerShell scripts...



'Matthew' on Tue, 21 Aug 2007 02:28:17 GMT, sez:

AND "Customer"."OrderDate"<{ts '2007-08-17 00:00:01'})

is probably even better as:

AND "Customer"."OrderDate"< = '20070817'



'Haacked' on Tue, 21 Aug 2007 04:42:51 GMT, sez:

so is this post about your lack of Google Fu?
;)



'lb' on Tue, 21 Aug 2007 04:44:57 GMT, sez:

>so is this post about your
>lack of Google Fu?

sure looks that way!

i guess i didn't really google too hard.

i was more excited by the idea that there might be this whole bunch of terse little secret commands in SQL that could perform all kinds of complex things.



'Mike Woodhouse' on Tue, 21 Aug 2007 06:07:15 GMT, sez:

Crystal. Bah. I stopped caring when their "wonderful" platform-agnostic SQL generator produced an Oracle outer-join operator for a SQL Server connection. About 1996 it was - geek grudges are forever.



'John Rusk' on Tue, 21 Aug 2007 06:40:48 GMT, sez:

I believe it's called the "ODBC Cannonical Datetime Format".



'Steve L' on Tue, 21 Aug 2007 06:54:39 GMT, sez:

Story ended too prematurely...

Should have also mentioned what fn and oj was... Which I presume are
fn = function
oj = outter join.



'Simon' on Tue, 21 Aug 2007 07:04:01 GMT, sez:

Google schmoogle. It's much more fun to knock up a powershell script just to see what happens. Your enthusiasm and curiosity are a wonder to behold. Secret, no. Geek, yes! Keep it up.



'ReallyVirtual' on Tue, 21 Aug 2007 08:59:00 GMT, sez:

Next step... the search for hidden 3 character keywords?



'Eric D. Burdo' on Tue, 21 Aug 2007 10:17:13 GMT, sez:

Wait until he hits the hidden 26 character keywords... that's going to take a bit.

:P



'Jon Schneider' on Wed, 22 Aug 2007 15:18:46 GMT, sez:

I'm with Simon. I got a much bigger kick out of the cool way that Leon ended up arriving at the answer in this case than from actually learning the answer itself! :-)



'Suraj Barkale' on Wed, 22 Aug 2007 23:24:43 GMT, sez:

When you have a scripting language, every problem screams to be scripted :)



'paul stovell' on Thu, 30 Aug 2007 08:38:28 GMT, sez:

The mean-spirited side of me hoped you might stumble accross the hidden "format C-drive" operator in your quest. The nice side of me is glad you didn't :)



'RV' on Fri, 09 Nov 2007 11:01:12 GMT, sez:

LOL! "so is this post about your lack of Google Fu?"



'andreas birgerson' on Wed, 14 Jul 2010 13:16:52 GMT, sez:

This is actually documented in
http://msdn.microsoft.com/en-us/library/ms378045(SQL.100).aspx




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. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Who reads this legal bit anyhow?

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.

TimeSnapper won last year's Developer Competition at Larkware.com, and is used by over 10,000 people.

Articles

JSON Query Languages: 5 special purpose editors JSON Query Languages: 5 special purpose editors
What then, is b? What then, is b?
SQLike: A simple editor SQLike: A simple editor
Yet Another BizPlan Generator. Yet Another BizPlan Generator.
HOT GUIDS: A hot or not site for guids HOT GUIDS: A hot or not site for guids
How does life get better? One tiny hack at a time. How does life get better? One tiny hack at a time.
24 things to do, and 100 things *not* to do (yet) for building a MicroISV 24 things to do, and 100 things *not* to do (yet) for building a MicroISV
Venture capital won't kill Jeff Atwood, it will only make him Jeffer. Venture capital won't kill Jeff Atwood, it will only make him Jeffer.
A handy workflow image for newbie mercurial users A handy workflow image for newbie mercurial users
Fractal Feedback, a diversion into recreational programming Fractal Feedback, a diversion into recreational programming
Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe. Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe.
Suggested User Experience Improvements for DiffMerge Suggested User Experience Improvements for DiffMerge
SQL Style Extensions for C# SQL Style Extensions for C#
The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's
Sysi: the ultimate administrators toolkit Sysi: the ultimate administrators toolkit

Archives .: secretGeek :: Complete Archives
TimeSnapper -- Automated Screenshot Journal TimeSnapper.com    
Version 3.3: true productivity boost

Next Action NextAction
Managing the top of your mind

World's Simplest Code Generator (html edition) World's Simplest Code Generator

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 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
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
ShuffleText - fuzzy search for .net
PC Smart Buys - Computer Hardware in Australia
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

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