0

I am on SQL Server 2008 R2 Management Studio and I was trying to export a table to SQL file as INSERT INTO... but in that table I have also a smalldatetime field which is gonna exported as CAST(0x9E7501E0 AS SmallDateTime) for example... is there a way to export that smalldatetime to .sql where smalldatetime would be represented as '2014-02-05 11:10:34' ?

thanks in advance to everyone!! Cheers, Luigi

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Luigino
  • 745
  • 3
  • 7
  • 26

2 Answers2

0

You can use Convert, which has lots of data format options:

See: http://www.w3schools.com/sql/func_convert.asp or How to convert DateTime to VarChar for examples.

Community
  • 1
  • 1
Anthony Horne
  • 2,522
  • 2
  • 29
  • 51
0

Use CONVERT function like

select CONVERT(smalldatetime, your_date_time_field, 120) as new_date_time

(OR)

If you want to convert it to varchar

select CONVERT(varchar, your_date_time_field, 120) as new_date_time

Here 120 is the format style which will represent the output as yy-mm-dd h:m:s

Rahul
  • 76,197
  • 13
  • 71
  • 125
  • @luigino, What I understood is: you have a table with few columns as `smalldatetime` data type and you want to export that table as SQL script ... right? Does the answer I have provided helps you? If no then please explain what is that you are trying to do. provide your table schema with some sample data ... can try it once and let you know how do go further. – Rahul May 02 '14 at 17:31