title: SQL Server getdate() to a string like "2009-12-20"
body: <p>In Microsoft SQL Server 2005 and .NET 2.0, I want to convert the current date to a string of this format:  "YYYY-MM-DD".  For example, December 12th 2009 would become "2009-12-20".  How do I do this in SQL.</p>
  
  <p>The context of this SQL statement in the table definiton. In other words, this is the default value.  So when a new record is created the default value of the current date is stored as a string in the above format.</p>
  
  <p>I'm trying: 
  SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD]</p>
  
  <p>But SQL server keeps converting that to:
  ('SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD]')</p>
  
  <p>so the result is just:</p>
  
  <p>'SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD]'</p>
  
  <p>Here's a screen shot of what the Visual Studio server explorer, table, table definition, properties shows:</p>
  
  <p><img src="https://farm3.static.flickr.com/2789/4201493342_351e53ed61_o.jpg" alt="alt text"></p>
  
  <p>These wrapper bits are being adding automatically and converting it all to literal string: (N' ')</p>
  
  <p>Here's the reason I'm trying to use something other than the basic DATETIME I was using previously:</p>
  
  <p>This is the error I get when hooking everything to an ASP.NET GridView and try to do an update via the grid view:</p>
  
  <h2>Server Error in '/' Application.</h2>
  
  <p>The version of SQL Server in use does not support datatype 'date'. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.ArgumentException: The version of SQL Server in use does not support datatype 'date'.</p>
  
  <p>Source Error: </p>
  
  <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  </p>
  
  <p>Stack Trace: </p>
  
  <p>[ArgumentException: The version of SQL Server in use does not support datatype 'date'.]</p>
  
  <p>Note: I've added a related question to try to get around the <a href="https://stackoverflow.com/questions/1937237/the-version-of-sql-server-in-use-does-not-support-datatype-date">SQL Server in use does not support datatype 'date' error</a> so that I can use a DATETIME as recommended.</p>