If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Date Conversion Issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-28-11, 16:16
ilfoprog ilfoprog is offline
Registered User
 
Join Date: Nov 2011
Posts: 3
Date Conversion Issue

Hello programmers. I was running a SP for the past couple of years. I dropped it to create it again with an additional column included (cmpcode). Now I get the below error message. Can someone help me with resolving this? Thank you. See attached.

CODE:
CREATE PROC BLTextData

@pay_date DATETIME

AS

DELETE zoas_apcheckinfo

INSERT zoas_apcheckinfo
SELECT cmpcode,
invno,
vendor,
paydate,
doccode,
checkno,
invamt,
checkamt,
status,
duedate,
year,
period,
docdate,
vendorname,
docnum

FROM oas_apcheckinfo
WHERE paydate = @pay_date
ORDER BY vendor

ERROR:
Msg 257, Level 16, State 3, Procedure BLTextData, Line 11
Implicit conversion from data type datetime to smallint is not allowed. Use the CONVERT function to run this query.
Attached Files
File Type: doc BLTextData Conversion Error.doc (92.0 KB, 1 views)
Reply With Quote
  #2 (permalink)  
Old 11-28-11, 16:53
PracticalProgram PracticalProgram is offline
Registered User
 
Join Date: Sep 2001
Location: Chicago, Illinois, USA
Posts: 551
So the error says that you are trying to push a datetime value into a smallint field.

Is it possible that you are accidentally doing that???
__________________
Ken

Maverick Software Design

(847) 864-3600 x2
Reply With Quote
  #3 (permalink)  
Old 11-28-11, 19:26
ilfoprog ilfoprog is offline
Registered User
 
Join Date: Nov 2011
Posts: 3
Ok, thanks for the reply. I figured it out. I had one of my columns out of order.
Reply With Quote
  #4 (permalink)  
Old 11-30-11, 03:43
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
You just found out why it is better to write INSERT scrpits like this:
Code:
INSERT zoas_apcheckinfo (cmpcode, invno, vendor,
   paydate, doccode, checkno,
   invamt, checkamt, status,
   duedate, year, period,
   docdate, vendorname, docnum)
SELECT cmpcode, invno, vendor,
   paydate, doccode, checkno,
   invamt, checkamt, status,
   duedate, year, period,
   docdate, vendorname, docnum
FROM oas_apcheckinfo
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
Reply

Tags
database, microsoft, sql

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On