怎样在sql语句中设定查询结果返回的格式?比如查询时间时按要求返回时间的格式

解决方案 »

  1.   

    CONVERT(CHAR(8),GETDATE(),112) 
    0 或 100 (*)  默认值 mon dd yyyy hh:miAM(或 PM) 
    1 101 美国 mm/dd/yyyy 
    2 102 ANSI yy.mm.dd 
    3 103 英国/法国 dd/mm/yy 
    4 104 德国 dd.mm.yy 
    5 105 意大利 dd-mm-yy 
    6 106 - dd mon yy 
    7 107 - mon dd, yy 
    8 108 - hh:mm:ss 
    - 9 或 109 (*)  默认值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM) 
    10 110 美国 mm-dd-yy 
    11 111 日本 yy/mm/dd 
    12 112 ISO yymmdd 
    - 13 或 113 (*)  欧洲默认值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h) 
    14 114 - hh:mi:ss:mmm(24h) 
    - 20 或 120 (*)  ODBC 规范 yyyy-mm-dd hh:mm:ss[.fff] 
    - 21 或 121 (*)  ODBC 规范(带毫秒) yyyy-mm-dd hh:mm:ss[.fff] 
    - 126(***) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(不含空格) 
    - 130* 科威特 dd mon yyyy hh:mi:ss:mmmAM 
    - 131* 科威特 dd/mm/yy hh:mi:ss:mmmAM 
      

  2.   

    Convert(类型,变量) ;
    Cast(变量 AS 类型) ;
      

  3.   

    返回的格式是你定的。你想要什么样的就把它转换成什么样的。如时间 的你可以 StrDate .StrToTime.StrToDate ,都是可以的。只是查询时的时间段在你想要的这些记录里就行了。  还可以用 Format() 都可以的。 以上引用的是 SysUtils 。
    祝你好运!!
      

  4.   

    这是t -sql 的帮助,你看一下吧:
    用 set dateformat 就可以确定sql 的日期输出格式。Sets the order of the dateparts (month/day/year) for entering datetime or smalldatetime data. 
    SyntaxSET DATEFORMAT {format | @format_var}Argumentsformat | @format_varIs the order of the dateparts. Can be either Unicode or DBCS converted to Unicode. Valid parameters include mdy, dmy, ymd, ydm, myd, and dym. The U.S. English default is mdy.ResThis setting is used only in the interpretation of character strings as they are converted to date values. It has no effect on the display of date values.
    The setting of SET DATEFORMAT is set at execute or run time and not at parse time.PermissionsSET DATEFORMAT permissions default to all users.ExamplesThis example uses different date formats to handle date strings in different formats.SET DATEFORMAT mdyGODECLARE @datevar datetimeSET @datevar = '12/31/98'SELECT @datevarGO  SET DATEFORMAT ydmGODECLARE @datevar datetimeSET @datevar = '98/31/12'SELECT @datevarGO  SET DATEFORMAT ymdGODECLARE @datevar datetimeSET @datevar = '98/12/31'SELECT @datevarGO
      

  5.   

    你可以看一下,delphi 自带的帮助文件,介绍的很清楚的。