Home All Groups Group Topic Archive Search About

referencing expressions in Select

Author
23 Nov 2006 2:01 AM
ChrisA
I'm hoping SQL can allow me to refer to an expression in a Select, but
can't find any syntax; I suppose that a function might work.  Here's the
problem:

  I've got a existing DB table with a date stored as an integer, so to
convert it to a datetime, I do:

  Select Cast(Cast(OrderDate as Char(8)) as dateTime)

  However, I'd like to be able to use this same expression in the Where
clause.  But it's an ugly mess, repeating it over and over.  Is there no way
to give the expression a name??

  The company uses these yyyymmdd integers all over, so that's one part of
the problem, the second is that having to repeat ANY expression seems
inefficient.

  Thanks

AddThis Social Bookmark Button