我正在尝试执行以下查询,并且不断收到此错误:
消息257,级别16,状态3,过程spRptTenRentRolldbs1,第802行[批处理开始第3行] 不允许从数据类型datetime到int的隐式转换。使用CONVERT函数运行此查询。
每个循环似乎出现1个错误。
USE [DBs1]
GO
SELECT ROW_NUMBER() OVER (ORDER BY siteid) AS rownum, siteid INTO rowsiteRentRoll FROM dbo.sites
CREATE TABLE temptableRentRoll
(
SiteID1 INT,
LedgerID INT,
sUnit VARCHAR (200),
sSize VARCHAR (200),
Area1 DECIMAL (19,2),
UnitID INT,
SiteID INT,
EmployeeID INT ,
UnitTypeID INT,
UnitZoneID VARCHAR (200),
MapRAID_Row VARCHAR (200),
MapRAID_Aisle VARCHAR (200),
sTrackingCode VARCHAR (200),
sRFID VARCHAR (200),
sGlobalUnitName VARCHAR (200),
TransferredTo_sGlobalSiteNum VARCHAR (200),
TransferredFrom_sGlobalSiteNum VARCHAR (200),
dTransferred DATETIME ,
TransferredBy_EmployeeID INT,
sUnitName VARCHAR (200),
iWalkThruOrder INT,
iFloor INT,
dcWidth INT,
dcLength INT,
dcMapTop VARCHAR (200),
dcMapLeft VARCHAR (200),
dcMapTheta VARCHAR (200),
bMapReversWL VARCHAR (200),
dcPushRate DECIMAL (19,2),
dcStdRate DECIMAL (19,2),
dcStdWeeklyRate DECIMAL (19,2),
dcStdSecDep DECIMAL (19,2),
dcStdLateFee DECIMAL (19,2),
bPower INT,
bClimate INT,
bInside INT,
bAlarm INT,
bRentable INT,
bRented INT,
dCreated DATETIME,
dDeleted DATETIME,
sUnitNote VARCHAR (600),
dUnitNote DATETIME,
sOSSType VARCHAR (200),
bCorporate VARCHAR (200),
bMobile VARCHAR (200),
dBuilt DATETIME,
dFirstInService DATETIME,
iMobileStatus VARCHAR (200),
bDamaged VARCHAR (200),
dDamaged DATETIME,
bCollapsible VARCHAR (200),
EmployeeID_BuiltBy VARCHAR (200),
bPermanent VARCHAR (200),
dUpdated DATETIME,
uTS VARCHAR(200),
OldPK INT,
MarketID_Whse INT,
sUnitDesc VARCHAR (200),
iEntryLoc VARCHAR (200),
dArchived DATETIME,
bExcludeFromSqftReports VARCHAR (200),
bExcludeFromWebsite VARCHAR (200),
bNotReadyToRent VARCHAR (200),
dcSchedRateMonthly DECIMAL (19,2),
dSchedRateMonthStrt DATETIME,
dcSchedRateWeekly DECIMAL (19,2),
dSchedRateWeeklyStrt DATETIME,
iADA INT,
iDoorType VARCHAR (200),
iVehicleStorageAllowed VARCHAR (200),
iDaysVacant VARCHAR (200),
dcWebRate DECIMAL (19,2),
dcWebPushRate DECIMAL (19,2),
LockID VARCHAR (200),
Area DECIMAL (19,2),
sTaxExempt VARCHAR (200),
sTenant VARCHAR (400),
sCompany VARCHAR (400),
iAnnivDays INT,
dLeaseDate DATETIME,
dcSecDep DECIMAL (19,2),
dcStandardRate DECIMAL (19,2),
dcRent DECIMAL (19,2),
dcVar DECIMAL (19,2),
dSchedRentStrt DATETIME,
dcSchedRent DECIMAL (19,2),
dcChargeBalance DECIMAL (19,2),
dPaidThru DATETIME,
dcPrePaidRentLiability DECIMAL (19,2),
CreditCardID DECIMAL (19,2),
dRentLastChanged DATETIME,
DaysSame DATETIME,
dSchedOut DATETIME,
TenantID INT,
sEmail VARCHAR (200),
dcInsurPremium DECIMAL (19,2),
dcPushRateAtMoveIn DECIMAL (19,2),
iAutoBillType INT
)
DECLARE @enddate datetime
SET @enddate = DATEADD(ss, -1, DATEADD(month, DATEDIFF(month, 0, getdate()), 0))
DECLARE @maxrow INT
SET @maxrow = (SELECT COUNT(siteid) FROM rowsiteRentRoll)
DECLARE @row INT
SET @row = 1
WHILE(@row <= @maxrow)
BEGIN
DECLARE @siteidrow INT
SET @siteidrow = (SELECT siteid FROM rowsiteRentRoll WHERE rownum = @row)
INSERT INTO temptableRentRoll
(
SiteID1,
LedgerID,
sUnit,
sSize,
Area1,
UnitID,
SiteID,
EmployeeID,
UnitTypeID,
UnitZoneID,
MapRAID_Row,
MapRAID_Aisle,
sTrackingCode,
sRFID,
sGlobalUnitName,
TransferredTo_sGlobalSiteNum,
TransferredFrom_sGlobalSiteNum,
dTransferred,
TransferredBy_EmployeeID,
sUnitName,
iWalkThruOrder,
iFloor,
dcWidth,
dcLength,
dcMapTop,
dcMapLeft,
dcMapTheta,
bMapReversWL,
dcPushRate,
dcStdRate,
dcStdWeeklyRate,
dcStdSecDep,
dcStdLateFee,
bPower,
bClimate,
bInside,
bAlarm,
bRentable,
bRented,
dCreated,
dDeleted,
sUnitNote,
dUnitNote,
sOSSType,
bCorporate,
bMobile,
dBuilt,
dFirstInService,
iMobileStatus,
bDamaged,
dDamaged,
bCollapsible,
EmployeeID_BuiltBy,
bPermanent,
dUpdated,
uTS,
OldPK,
MarketID_Whse,
sUnitDesc,
iEntryLoc,
dArchived,
bExcludeFromSqftReports,
bExcludeFromWebsite,
bNotReadyToRent,
dcSchedRateMonthly,
dSchedRateMonthStrt,
dcSchedRateWeekly,
dSchedRateWeeklyStrt,
iADA,
iDoorType,
iVehicleStorageAllowed,
iDaysVacant,
dcWebRate,
dcWebPushRate,
LockID,
Area,
sTaxExempt,
sTenant,
sCompany,
iAnnivDays,
dLeaseDate,
dcSecDep,
dcStandardRate,
dcRent,
dcVar,
dSchedRentStrt,
dcSchedRent,
dcChargeBalance,
dPaidThru,
dcPrePaidRentLiability,
CreditCardID,
dRentLastChanged,
DaysSame,
dSchedOut,
TenantID,
sEmail,
dcInsurPremium,
dcPushRateAtMoveIn,
iAutoBillType
)
EXEC dbo.spRptTenRentRolldbs1
@SiteID = @siteidrow,
@dEnd = @enddate,
@Filter = '100'
SET @row = @row + 1
END
我已经读到,如果表定义与插入的内容不匹配,我会检查并确保所有内容都匹配。
在这一点上,我不得不假设我对其中一列的数据类型进行了误分类。我只是从输出中看到的内容开始,一些列仅包含NULL值,因此我不确定它们是什么,必须进行有根据的猜测。
不幸的是,这利用了一个非常复杂的SP,该SP引用了所有其他功能和SP。我试图避免将每一列追溯到原始位置来确定数据类型。
如何读取错误以确定问题所在的列?我尝试过查询中的第802行(不存在)和存储过程(没有任何意义)。我认为循环可能会使事情复杂化?
更新
我能够使用以下方法拉出SP返回的所有数据类型:
EXEC sp_describe_first_result_set N'dbo.spRptTenRentRolldbs1'
我更新了代码,以使用上面返回的确切数据类型:
SELECT ROW_NUMBER() OVER (ORDER BY siteid) AS rownum, siteid INTO rowsiteRentRoll FROM dbo.sites
CREATE TABLE temptableRentRoll
(
SiteID1 int,
LedgerID int,
sUnit nvarchar(6),
sSize varchar(4),
Area1 money,
UnitID int,
SiteID int,
EmployeeID int,
UnitTypeID int,
UnitZoneID int,
MarketID_Whse int,
MapRAID_Row int,
MapRAID_Aisle int,
sTrackingCode nvarchar(30),
sRFID nvarchar(30),
sGlobalUnitName nvarchar(30),
TransferredTo_sGlobalSiteNum nvarchar(20),
TransferredFrom_sGlobalSiteNum nvarchar(20),
dTransferred datetime,
TransferredBy_EmployeeID int,
sUnitName nvarchar(6),
iWalkThruOrder int,
iFloor int,
dcWidth money,
dcLength money,
dcMapTop money,
dcMapLeft money,
dcMapTheta money,
bMapReversWL bit,
dcPushRate money,
dcStdRate money,
dcStdWeeklyRate money,
dcStdSecDep money,
dcStdLateFee money,
bPower bit,
bClimate bit,
bInside bit,
bAlarm bit,
bRentable bit,
bRented bit,
dCreated datetime,
dDeleted datetime,
sUnitNote nvarchar(150),
dUnitNote datetime,
sOSSType nvarchar(10),
bCorporate bit,
bMobile bit,
dBuilt datetime,
dFirstInService datetime,
iMobileStatus int,
bDamaged bit,
dDamaged datetime,
bCollapsible bit,
EmployeeID_BuiltBy int,
sUnitDesc nvarchar(50),
iEntryLoc int,
bExcludeFromSqftReports bit,
bExcludeFromWebsite bit,
bNotReadyToRent bit,
iADA int,
iDoorType int,
iVehicleStorageAllowed int,
dArchived datetime,
bPermanent bit,
dUpdated datetime,
uTS binary (8),
OldPK int,
dcSchedRateMonthly money,
dSchedRateMonthStrt datetime,
dcSchedRateWeekly money,
dSchedRateWeeklyStrt datetime,
iDaysVacant int,
dcWebRate money,
dcWebPushRate money,
LockID int,
Area money,
sTaxExempt nvarchar(1),
sTenant nvarchar(100),
sCompany nvarchar(80),
iAnnivDays int,
dLeaseDate datetime,
dcSecDep money,
dcStandardRate money,
dcRent money,
dcVar money,
dSchedRentStrt datetime,
dcSchedRent money,
dcChargeBalance money,
dPaidThru datetime,
dcPrePaidRentLiability numeric(38,4),
CreditCardID int,
dRentLastChanged datetime,
DaysSame int,
dSchedOut datetime,
TenantID int,
sEmail nvarchar(100),
dcInsurPremium money,
dcPushRateAtMoveIn money,
iAutoBillType int
)
DECLARE @enddate datetime
SET @enddate = DATEADD(ss, -1, DATEADD(month, DATEDIFF(month, 0, getdate()), 0))
DECLARE @maxrow INT
SET @maxrow = (SELECT COUNT(siteid) FROM rowsiteRentRoll)
DECLARE @row INT
SET @row = 1
WHILE(@row <= @maxrow)
BEGIN
DECLARE @siteidrow INT
SET @siteidrow = (SELECT siteid FROM rowsiteRentRoll WHERE rownum = @row)
INSERT INTO temptableRentRoll
(
SiteID1,
LedgerID,
sUnit,
sSize,
Area1,
UnitID,
SiteID,
EmployeeID,
UnitTypeID,
UnitZoneID,
MapRAID_Row,
MapRAID_Aisle,
sTrackingCode,
sRFID,
sGlobalUnitName,
TransferredTo_sGlobalSiteNum,
TransferredFrom_sGlobalSiteNum,
dTransferred,
TransferredBy_EmployeeID,
sUnitName,
iWalkThruOrder,
iFloor,
dcWidth,
dcLength,
dcMapTop,
dcMapLeft,
dcMapTheta,
bMapReversWL,
dcPushRate,
dcStdRate,
dcStdWeeklyRate,
dcStdSecDep,
dcStdLateFee,
bPower,
bClimate,
bInside,
bAlarm,
bRentable,
bRented,
dCreated,
dDeleted,
sUnitNote,
dUnitNote,
sOSSType,
bCorporate,
bMobile,
dBuilt,
dFirstInService,
iMobileStatus,
bDamaged,
dDamaged,
bCollapsible,
EmployeeID_BuiltBy,
bPermanent,
dUpdated,
uTS,
OldPK,
MarketID_Whse,
sUnitDesc,
iEntryLoc,
dArchived,
bExcludeFromSqftReports,
bExcludeFromWebsite,
bNotReadyToRent,
dcSchedRateMonthly,
dSchedRateMonthStrt,
dcSchedRateWeekly,
dSchedRateWeeklyStrt,
iADA,
iDoorType,
iVehicleStorageAllowed,
iDaysVacant,
dcWebRate,
dcWebPushRate,
LockID,
Area,
sTaxExempt,
sTenant,
sCompany,
iAnnivDays,
dLeaseDate,
dcSecDep,
dcStandardRate,
dcRent,
dcVar,
dSchedRentStrt,
dcSchedRent,
dcChargeBalance,
dPaidThru,
dcPrePaidRentLiability,
CreditCardID,
dRentLastChanged,
DaysSame,
dSchedOut,
TenantID,
sEmail,
dcInsurPremium,
dcPushRateAtMoveIn,
iAutoBillType
)
EXEC dbo.spRptTenRentRolldbs1
@SiteID = @siteidrow,
@dEnd = @enddate,
@Filter = '100'
SET @row = @row + 1
END
以某种方式,我仍在不同的批处理起始行中收到相同的错误消息:
消息257,级别16,状态3,过程spRptTenRentRolldbs1,第802行[批处理开始第6行] 不允许从数据类型datetime到int的隐式转换。使用CONVERT函数运行此查询。
据我所知这应该是不可能的,我提取了SP返回的确切数据类型,并使其成为我的表定义。这怎么可能??
答案 0 :(得分:0)
对其他有类似问题的人的简洁答案...
我的数据类型最终出了点问题。我不知道具体是什么问题,因为我找到了一种直接从SP覆盖标签的数据标签的方法。
我运行它来获取SP返回的所有数据类型的列表:
EXEC sp_describe_first_result_set N'dbo.spRptTenRentRolldbs1'
然后我将结果集转储到excel中,以快速重新创建表创建代码。然后,我修改了查询以包含新的数据类型,并“最终”解决了我的问题。
我之所以说“最终”,是因为我遇到了另一个问题,即我不小心将其中一个列放错了顺序,并导致了我最初收到的相同错误消息-因此看来,这个特定错误不一定意味着您有数据类型转换问题。
似乎也可能意味着表创建/定义结构有问题。