获取错误:从字符串转换日期和/或时间时转换失败

时间:2016-05-11 07:55:08

标签: sql-server

apply plugin: 'com.android.application'
repositories {
    mavenCentral()
    maven {
        name 'maven.aviary.com'
        url uri("http://maven.aviary.com/repo/release")
    }
}
android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"


    defaultConfig {
        applicationId "com.dnuon.aviarydemo"
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


    packagingOptions {
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
    }
    [enter image description here][1]
}

dependencies {
    compile 'com.aviary.android.feather.sdk:aviary-sdk:3.4.3.351'
    compile fileTree(dir: 'libs', include: ['*.jar'])
} 

2 个答案:

答案 0 :(得分:2)

尝试转换日期/日期时间列,如下所示:

SELECT
 LEFT( DATENAME( MONTH, CONVERT(datetime, TRIPDATE, 103))
 ,3 ) + ' ' + RIGHT(DATENAME(YEAR, convert(datetime, TRIPDATE, 103)),2 ) AS [MonthYear],
 SUM(ISNULL(cast(TOTALFREIGHT as float),0)) AS FreightAmount 
FROM OFFLINETRANS 
Group By  LEFT( DATENAME( MONTH, CONVERT(datetime, TRIPDATE, 103)) ,3 ) + ' ' + RIGHT(DATENAME(YEAR, convert(datetime, TRIPDATE, 103)),2 )
ORDER BY max(TRIPDATE)

编辑:不要编辑我的答案,如果你仍有问题,请编辑自己的问题。如果新问题与原始帖子无关,请改为创建新问题。

答案 1 :(得分:0)

SELECT [MonthYear],SUM(CAST(FreightAmount AS DECIMAL(18,2))) As FreightAmount
FROM (
 SELECT LEFT(DateName(Month, TRIPDATE), 3) + ' ' + RIGHT(DateName(Year, TRIPDATE), 2) AS [MonthYear] ,SUM(TRIPCOST) AS FreightAmount ,max(TRIPDATE) AS UsedForOrder
   FROM TRANSVIEW GROUP BY DateName(Month, TRIPDATE) ,DateName(Year, TRIPDATE)

UNION ALL
 SELECT LEFT(DATENAME(MONTH, CONVERT(DATETIME, TRIPDATE, 103)), 3) + ' ' + RIGHT(DATENAME(YEAR, convert(DATETIME, TRIPDATE, 103)), 2) AS [MonthYear] ,SUM(ISNULL(cast(TOTALFREIGHT AS FLOAT), 0)) AS FreightAmount ,max(CONVERT(DATETIME, TRIPDATE, 103)) AS UsedForOrder FROM OFFLINETRANS GROUP BY LEFT(DATENAME(MONTH, CONVERT(DATETIME, TRIPDATE, 103)), 3) + ' ' + RIGHT(DATENAME(YEAR, convert(DATETIME, TRIPDATE, 103)), 2)

) AS A GROUP BY [MonthYear] ORDER BY max(UsedForOrder)