How to get DATE from DATETIME Column in SQL?
本问题已经有最佳答案,请猛点这里访问。
我在SQL Server的TransactionMaster表中有3列
1)交易金额
2)卡德诺
3)事务处理日期——
所以,我想取
只需将时间戳强制转换为cx1(1),如下所示:
1 | SELECT CAST(tstamp AS DATE) |
SQLFiddle演示
换句话说,您的陈述如下:
1 2 3 4 | SELECT SUM(transaction_amount) FROM mytable WHERE Card_No='123' AND CAST(transaction_date AS DATE) = target_date |
你可以使用
1 2 3 | SELECT * FROM TRANSACTION WHERE (Card_No='123') AND (transaction_date = CONVERT(VARCHAR(10),getdate(),101)) |
使用
1 2 | SELECT SUM(transaction_amount) FROM TransactionMaster WHERE Card_No=' 123' AND transaction_date =CONVERT(VARCHAR(10), getdate(), 102) |
使用以下内容
1 2 | SELECT SUM(transaction_amount) FROM TransactionMaste WHERE Card_No = '123' AND transaction_date = CONVERT(VARCHAR(10),GETDATE(),111) |
或以下内容
1 2 | SELECT SUM(transaction_amount) FROM TransactionMaste WHERE Card_No = '123' AND transaction_date = CONVERT(VARCHAR(10), GETDATE(), 120) |
试试这个:
1 | SELECT SUM(transaction_amount) FROM TransactionMaster WHERE Card_No ='123' AND CONVERT(VARCHAR(10),GETDATE(),111) |