将字符串转换为datetime,将int转换为datetime [英] Convert string to datetime and int to datetime
本文介绍了将字符串转换为datetime,将int转换为datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谢谢你提前
以下是我的查询,所以我可以从这个月和一年中选择一个到这个月和一年来显示它们的价值
ssql = SELECT Temp_Portal.Project_Total,Temp_Portal.Project,Temp_Portal.Billing_Month,Temp_Portal.Billing_Year, Temp_Portal.Project_Code& _
FROM MTS_Portal.dbo.Temp_Portal Temp_Portal& _
WHERE Temp_Portal.Project_Code LIKE'%BD%'AND((Temp_Portal.Billing_Month ='& Trim(Me.cboToMonth。 Text )& ')AND(Temp_Portal.Billing_Year =& Trim(Me.cboFromYear。 Text )& ))或((Temp_Portal.Billing_Month ='& Trim(Me.cboFromMonth。文字)& ')AND(Temp_Portal.Billing_Year =& Trim (Me.cboToYear。 Text )& ))
解决方案
试试这个:
DECLARE @ Billing_Year INT , @ Billing_Month VARCHAR ( 20 )
SET @ Billing_Year = 2014
SET @ Billing_Month = ' 八月'
SELECT CAST(CAST( @ Billing_Year AS VARCHAR ( 4 ))+ ' - ' + @ Billing_Month + ' - ' + ' 01' AS DATE )
如果可能,您应该创建一个bill_date日期类型并存储开票日期,然后您可以使用sql检索任何月份的所有记录。
hi everyone, i just want to ask for you help. i have this field Billing_Month which is string and Billing_Year which is int, i want this both field to convert as datetime, is there anyone who can help me?
Thanks in advance
below is my query so i can select a from this month and year to this month and year to display their value
ssql = " SELECT Temp_Portal.Project_Total, Temp_Portal.Project, Temp_Portal.Billing_Month, Temp_Portal.Billing_Year, Temp_Portal.Project_Code" & _
" FROM MTS_Portal.dbo.Temp_Portal Temp_Portal " & _
" WHERE Temp_Portal.Project_Code LIKE '%BD%' AND ((Temp_Portal.Billing_Month = '" & Trim(Me.cboToMonth.Text) & "') AND (Temp_Portal.Billing_Year = " & Trim(Me.cboFromYear.Text) & ")) OR ((Temp_Portal.Billing_Month = '" & Trim(Me.cboFromMonth.Text) & "') AND (Temp_Portal.Billing_Year = " & Trim(Me.cboToYear.Text) & "))"
解决方案
Try this:
DECLARE @Billing_Year INT, @Billing_Month VARCHAR(20) SET @Billing_Year = 2014 SET @Billing_Month = 'August' SELECT CAST(CAST(@Billing_Year AS VARCHAR(4))+ '-' + @Billing_Month + '-' + '01' AS DATE)
If possible, you should create a bill_date of date type and store the date of billing, you can then use sql to retrieve all records for any month.
这篇关于将字符串转换为datetime,将int转换为datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文