SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


conversion error data type - Error msg inserting


conversion error data type - Error msg inserting

Author
Message
GrassHopper
GrassHopper
SSC Veteran
SSC Veteran (285 reputation)SSC Veteran (285 reputation)SSC Veteran (285 reputation)SSC Veteran (285 reputation)SSC Veteran (285 reputation)SSC Veteran (285 reputation)SSC Veteran (285 reputation)SSC Veteran (285 reputation)

Group: General Forum Members
Points: 285 Visits: 537
When I run the Select statement without the insert, it does not return any records. I don't know why I get the error msg below.

I get the following error msg when running the code below:
Msg 257, Level 16, State 3, Line 3
Implicit conversion from data type smalldatetime to int is not allowed. Use the CONVERT function to run this query.



If (Select top 1 Tab03ID From SubQryTab05_SubTab02forAppend) IS NOT NULL
BEGIN
INSERT INTO Tab06_SubTab02 (
GroupID, AssignedAuditors, Include, InTrans, Pricing, IncludeSample, VndNbrAlt, ItemClientStyleKey, CltStyle, RecNo, PdItmNetCst, PdQty, OutBal, PONbr, PODt, POItmGrsCst, POItmNetCst, POQty, InvNbr, InvDt, InvShpDt
, InvItmGrsCst, InvItmNetCst, InvQty, RcvNbr, RcvDt, RcvItmGrsCst, RcvItmNetCst, RcvQty, DptNbr, MerchEffDt, MerchEffDtCode, PPInvDt, LastUpdatedBy, LastUpdatedDate, AuditPeriodKey, FactBalancingDetailKey, ActiveFlag, LoadDt, MoveToWS, Sample
, Comments, Tab05_SubTab02ID, Tab03ID, Tab02ID )
SELECT
'130400017', 'abenit01', Include, InTrans, Pricing, IncludeSample, VndNbrAlt, ItemClientStyleKey, CltStyle, RecNo, PdItmNetCst, PdQty, OutBal, PONbr, PODt, POItmGrsCst, POItmNetCst, POQty, InvNbr, InvDt, InvShpDt
, InvItmGrsCst, InvItmNetCst, InvQty, RcvNbr, RcvDt, RcvItmGrsCst, RcvItmNetCst, RcvQty, DptNbr, MerchEffDt, MerchEffDtCode, PPInvDt, LastUpdatedBy, LastUpdatedDate, AuditPeriodKey, FactBalancingDetailKey, ActiveFlag, LoadDt, MoveToWS, Sample
, Comments, Tab05_SubTab02ID, Tab03ID, Tab02ID
FROM SubQryTab05_SubTab02forAppend
END



Michael L John
Michael L John
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3004 Visits: 7811
In the table Tab06_SubTab02, you have field defined as an integer.
The corresponding field in the select statement is a smalldatetime.

Even though there are no rows returned, SQL still compiles the query and throws a compile time error.

You need to match up the fields in the insert to the fields in the select and compare the data types. An integer field cannot be populated by a smalldatetime field.

As an easier example, this will throw the same error:

DECLARE @Tab TABLE
(
IntegerField int
)

DECLARE @smalldatetime smalldatetime

INSERT INTO @Tab(IntegerField)
SELECT @smalldatetime

Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search