嗨,我有以下查询,它给了我想要的结果,除了一件事。
我的查询:
(SELECT
(SELECT
'3' as '@CategoryDepth',
'CIMtrek_SelectedPage' as '@SelectedPage',
'CIMtrek_ParentID' as '@ParentID',
'CIMtrek_LstParm' as '@LstParm',
'CIMtrek_SearchParm' as '@SearchParm',
'CIMtrek_Search_No' as '@isSearch',
'CIMtrek_CDS1' as '@ViewName'
FOR XML PATH('AppConfig'), TYPE ),
(SELECT
RES.Header as '@Header'
FROM (
SELECT 'Date' AS Header
UNION ALL
SELECT 'MY MENU' AS Header
) AS RES
FOR XML PATH('ColumnHeader'), TYPE ),
(SELECT
RES.Param as '@Param'
FROM (
SELECT 'CIMtrek_daily_shipdate' AS Param
UNION ALL
SELECT 'MY PARM' AS Param
) AS RES
FOR XML PATH('Params'), TYPE ),
(SELECT
RES.Search as '@Search'
FROM (
SELECT 'Date|[T1].[CIMtrek_daily_shipdate] ' AS Search
UNION ALL
SELECT 'Department|[T1].[CIMtrek_daily_PackingMethod] ' AS Search
UNION ALL
SELECT 'Rush|[T1].[CIMtrek_daily_Rush] ' AS Search
UNION ALL
SELECT 'Customer Name|[T1].[CIMtrek_daily_CustomerName_1] ' AS Search
UNION ALL
SELECT 'Schedule Name|[T1].[CIMtrek_daily_schedule_name] ' AS Search
UNION ALL
SELECT 'Carrier|[T1].[CIMtrek_daily_carrier] ' AS Search
UNION ALL
SELECT 'Order|[T1].[CIMtrek_daily_order] ' AS Search
UNION ALL
SELECT 'Load #|[T1].[CIMtrek_daily_load] ' AS Search
UNION ALL
SELECT 'Pieces|[T1].[CIMtrek_daily_pieces] ' AS Search
UNION ALL
SELECT 'Cases|[T1].[CIMtrek_daily_cases] ' AS Search
UNION ALL
SELECT 'Weight|[T1].[CIMtrek_daily_weight] ' AS Search
UNION ALL
SELECT 'Cube|[T1].[CIMtrek_daily_cube] ' AS Search
UNION ALL
SELECT 'MY SEARCH|Search' AS Search
) AS RES
FOR XML PATH('Search'), TYPE ),
(SELECT
(
SELECT COUNT(*) FROM (
SELECT
ISNULL([T1].[CIMtrek_daily_shipdate],'') AS CIMtrek_daily_shipdate
FROM
[CIMtrek_SystemTable_DatawareHouse] [T1] WHERE LEN(LTRIM(RTRIM(ISNULL(LTRIM(RTRIM([T1].[CIMtrek_daily_shipdate])),'')))) != 0 AND
1 = 1
AND [T1].[CIMtrek_form] in ('Compliance Daily Shipments')
AND [T1].[CIMtrek_daily_status] not in ('Complete')
AND [T1].[CIMtrek_Archive] not in ('Archived')
GROUP BY
ISNULL([T1].[CIMtrek_daily_shipdate],'')
) AS COUNTS1
) AS '@CIMtrek_COUNT' ,
'1' AS '@CIMtrek_COUNT_Level',
(SELECT
[T1].[ROW] AS '@Row'
,newid() AS '@UnqCimID'
<!--
changed this to format date to be DD/MM/YYYY
, [T1].[CIMtrek_daily_shipdate] AS '@CIMtrek_daily_shipdate'
-->
,CONVERT(VARCHAR(10),[T1].[CIMtrek_daily_shipdate],106) AS '@CIMtrek_daily_shipdate'
FROM (SELECT
ROW_NUMBER() OVER(ORDER BY ISNULL([T1].[CIMtrek_daily_shipdate],'')
ASC) ROW
, ISNULL([T1].[CIMtrek_daily_shipdate],'') AS CIMtrek_daily_shipdate
FROM
[CIMtrek_SystemTable_DatawareHouse] [T1] WHERE LEN(LTRIM(RTRIM(ISNULL(LTRIM(RTRIM([T1].[CIMtrek_daily_shipdate])),'')))) != 0 AND
1 = 1
AND [T1].[CIMtrek_form] in ('Compliance Daily Shipments')
AND [T1].[CIMtrek_daily_status] not in ('Complete')
AND [T1].[CIMtrek_Archive] not in ('Archived')
GROUP BY
ISNULL([T1].[CIMtrek_daily_shipdate],'')
) T1
WHERE [T1].ROW BETWEEN 1 and 10
order by convert(date,[T1].[CIMtrek_daily_shipdate],103)
FOR XML PATH('Data'), TYPE
)FOR XML PATH('Data'), TYPE) )FOR XML PATH('Root')
在上面的查询中,我评论了以下行:
<!--
changed this to format date to be DD/MM/YYYY
, [T1].[CIMtrek_daily_shipdate] AS '@CIMtrek_daily_shipdate'
-->
并输入以下行
,CONVERT(VARCHAR(10),[T1].[CIMtrek_daily_shipdate],106) AS '@CIMtrek_daily_shipdate'
这会将日期转换为 : 01-Nov-12 12:00:00 AM
,01-Nov-12
它也很好,但在某些情况下我得到日期01-Nov-12 12:45:21 AM
,在这种情况下我必须显示日期和时间。
所以实际上我不应该显示日期时间是什么时候,而是显示日期时间是 01-Nov-12 12:00:00 AM
什么时候01-Nov-12 12:45:21 AM
。
如何在查询本身中处理这个问题?
请帮助我得到这个。
问候