2013-02-28 65 views
0
SELECT 

incident.createDate, 
LEFT(incident.createDate,11)as EntryDate, 
ContactDetails.cityCode, 
patient.insurance, 

FROM ...... 

WHERE 
incident.createDate Between Convert(smalldatetime, '01/07/2012', 103) and Convert(smalldatetime, '31/12/2012', 103) 
and servicecharges.serviceid = 31 
and ServiceRequestDescription LIKE '05.06%' 
and chargeDescr = 'Ε0 50.01' 
and incident.status != 6 
order by createDate ASC, contactdetails.cityCode ASC, patient.insurance ASC 

作爲輸出我得到SQL投日期時間,而不小時,訂貨問題也

15642  2012-08-03 11:45:07.153  Aug 3 2012   103  15 

我想要得到的是

15642  2012-08-03  103  15 

EntryDate蒙上日期以上,所以我不希望它。訂購也是錯誤的。它命令輸出與日期正確,但然後城市代碼和保險是不正確的。

任何想法?

+1

你正在使用什麼[RDBMS](http://en.wikipedia.org/wiki/Relational_database_management_system)? 'RDBMS'代表*關係數據庫管理系統*。 'RDBMS是SQL'的基礎,並且適用於所有現代數據庫系統,如MS SQL Server,IBM DB2,Oracle,MySQL等...... – 2013-02-28 08:50:35

+0

...和** SQL **只是**結構化查詢語言* * - 許多關係型數據庫使用的語言 - 單獨不會告訴我們您使用的是什麼**系統** ... – 2013-02-28 09:36:27

回答

0

試試這個

SELECT 
... 
CONVERT(Varchar, incident.createDate, 103) as EntryDate, 
ContactDetails.cityCode, 
patient.insurance, 

FROM ...... 
0

對於SQL-服務器:我覺得沒有direct format得到ONLYyyyy-mm-dd。您可以嘗試120/121,然後按如下所示獲取left 10 characters。小demo here

select left(convert(varchar,incident.createDate,120),10) as EntryDate