将数据类型varchar转换为datetime时出错。 [英] Error converting data type varchar to datetime.
本文介绍了将数据类型varchar转换为datetime时出错。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
exec [mob].[MobileGetCustomerLocationMap] @RequestUserID=14,@RequestType=0,@LastSyncDate='2016-07-05 09:10:12.4530000'
如何处理此类日期。我不是每次都在日期结束时得到额外的零..但是想要处理这个
我尝试了什么:
How can i handle this type of date. I dont get extra zero at the end of date everytime .. but want to handle this
What I have tried:
ALTER PROCEDURE [mob].[MobileGetCustomerLocationMap]
@RequestUserID INT,
@RequestType BIT,
@LastSyncDate DATETIME
As
BEGIN
IF (@RequestType = 1)
BEGIN
SET @LastSyncDate = NULL;
END
DECLARE @Customer Table
(
CustomerToCustomerLocationID INT ,
CustomerID int,
CustomerLocationID int,
IsDefault BIT,
IsInActive BIT,
UpdatedOn datetime
)
IF (@LastSyncDate IS NOT NULL)
BEGIN
INSERT INTO @Customer(CustomerToCustomerLocationID,IsInActive,UpdatedOn)
SELECT DISTINCT ccl.CustomerToCustomerLocationID,1,ccl.UpdatedOn
FROM UserToCustomerHistory uch
INNER JOIN CustomerToCustomerLocation ccl ON uch.CustomerID = uch.CustomerID
LEFT OUTER JOIN UserToCustomer uc ON uch.UserID = uc.UserID AND uch.CustomerID = uc.CustomerID AND uc.IsInActive = 0
WHERE uch.UserID = @RequestUserID AND uch.EndDate > @LastSyncDate AND uc.CustomerID IS NULL
END
推荐答案
IF (@RequestType = 1)
BEGIN
SET @LastSyncDate = NULL;
END
Declare @convDate datetime
set @convDate = CONVERT(VARCHAR(23), @LastSyncDate, 110)
DECLARE @Customer Table
(
CustomerToCustomerLocationID INT ,
CustomerID int,
CustomerLocationID int,
IsDefault BIT,
IsInActive BIT,
UpdatedOn datetime
)
IF (@LastSyncDate IS NOT NULL)
BEGIN
INSERT INTO @Customer(CustomerToCustomerLocationID,IsInActive,UpdatedOn)
SELECT DISTINCT ccl.CustomerToCustomerLocationID,1,ccl.UpdatedOn
FROM UserToCustomerHistory uch
INNER JOIN CustomerToCustomerLocation ccl ON uch.CustomerID = uch.CustomerID
LEFT OUTER JOIN UserToCustomer uc ON uch.UserID = uc.UserID AND uch.CustomerID = uc.CustomerID AND uc.IsInActive = 0
WHERE uch.UserID = @RequestUserID AND uch.EndDate > @convDate AND uc.CustomerID IS NULL
END
这篇关于将数据类型varchar转换为datetime时出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文