|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SQL Server 2000 View -- Case StatementIn a table I have a date format: YYYYMMDD
What do you do when instead of NULLs or Blank Dates there are 99999999? In Access I'd use an IIF statement. This case statement by itself doesn't work. Any ideas appreciated: SELECT CASE WHEN Col004 = '99999999' THEN IS NULL ELSE CONVERT(smalldatetime, Col004) AS MyDate FROM dbo.MyTable; Thanks, RBollinger Try this:
SELECT CASE WHEN Col004 = '99999999' THEN NULL ELSE CONVERT(smalldatetime, Col004) end AS MyDate FROM dbo.MyTable Show quote "robboll" wrote: > In a table I have a date format: YYYYMMDD > > What do you do when instead of NULLs or Blank Dates there are 99999999? > > In Access I'd use an IIF statement. > > This case statement by itself doesn't work. Any ideas appreciated: > > SELECT CASE WHEN Col004 = '99999999' THEN IS NULL ELSE > CONVERT(smalldatetime, Col004) AS MyDate > FROM dbo.MyTable; > > Thanks, > > RBollinger > > Thanks -- works great
Greg Larsen wrote: Show quote > Try this: > > SELECT CASE WHEN Col004 = '99999999' THEN NULL ELSE > CONVERT(smalldatetime, Col004) end AS MyDate > FROM dbo.MyTable > > "robboll" wrote: > > > In a table I have a date format: YYYYMMDD > > > > What do you do when instead of NULLs or Blank Dates there are 99999999? > > > > In Access I'd use an IIF statement. > > > > This case statement by itself doesn't work. Any ideas appreciated: > > > > SELECT CASE WHEN Col004 = '99999999' THEN IS NULL ELSE > > CONVERT(smalldatetime, Col004) AS MyDate > > FROM dbo.MyTable; > > > > Thanks, > > > > RBollinger > > > > IS NULL is a test, an assignment is simply NULL. And CASE requires an
END. SELECT CASE WHEN Col004 = '99999999' THEN NULL ELSE CONVERT(smalldatetime, Col004) END AS MyDate FROM dbo.MyTable; Roy Harvey Beacon Falls, CT Show quote On 22 Jun 2006 09:38:01 -0700, "robboll" <robb***@hotmail.com> wrote: >In a table I have a date format: YYYYMMDD > >What do you do when instead of NULLs or Blank Dates there are 99999999? > >In Access I'd use an IIF statement. > >This case statement by itself doesn't work. Any ideas appreciated: > >SELECT CASE WHEN Col004 = '99999999' THEN IS NULL ELSE >CONVERT(smalldatetime, Col004) AS MyDate >FROM dbo.MyTable; > >Thanks, > >RBollinger |
|||||||||||||||||||||||