Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello! I have a simple trouble, but dont understand what is wrong:

CSS
Errore in esecuzione ExecuteNonQuery
Errore : Error converting data type char to datetime.
Query : NdgRappUpdate


On input i have format date is: #2/25/2013 12:52:45 PM#

And there is SQL procedure:

SQL
CREATE PROCEDURE [dbo].[NdgRappUpdate]
	@TIPOINT		CHAR(2)
	,@CODINT		CHAR(11)
	,@CODNDG		CHAR(16)
	,@TPRAPP		CHAR(3)
	,@CHIAVERAPP	CHAR(50)
	,@TPCOLLNDGRAPP	CHAR(3)
	,@DTFINEOLD		DATETIME
	,@STATORIGA		CHAR(1)=NULL
	,@DATAELAB		DATETIME=NULL
	,@PROCELAB		CHAR(8)=NULL
AS
BEGIN
DECLARE @DTFINE DATETIME
		,@DTINIZIO DATETIME
SELECT @DTFINE = CONVERT(DATETIME,'12/31/9999',103)
		,@DTINIZIO = GETDATE()
....Any code SQL



The type of field "DATAELAB" at table is datetime

Say me true way in this question? Thank you!
Posted

hi,

try this coding,

SQL
DECLARE @DTFINE varchar(30)
        ,@DTINIZIO varchar(30)
SELECT @DTFINE = CONVERT(varchar(30),'12/31/9999',103)
        ,@DTINIZIO = GETDATE()



regards,
Prakash.T
 
Share this answer
 
Take off the "103" parameters - it specifies that SQL should expect two-digit dates, not four:
SQL
SELECT @DTFINE = CONVERT(DATETIME,'12/31/9999')
        ,@DTINIZIO = GETDATE()
 
Share this answer
 
First of all why you using 103 format when you just want to cast in Datetime, you can directly cast the string into datetime

SQL
SELECT CONVERT(DATETIME,'2/25/2013 12:52:45 PM')


so if you want any formatted output than you can use 101, 103 etc...

SQL
SELECT CONVERT(VARCHAR,CONVERT(DATETIME,'2/25/2013 12:52:45 PM'),101)  AS 'Format 101', CONVERT(VARCHAR,CONVERT(DATETIME,'2/25/2013 12:52:45 PM'),103) AS 'Format 103'


Result will be:

SQL
Format 101 | Format 103
------------------------
02/25/2013 | 25/02/2013
 
Share this answer
 
Try this -
DECLARE @DTFINE DATETIME
		,@DTINIZIO DATETIME
SELECT @DTFINE = CONVERT(DATETIME,'31/12/9999',103)  -- input date should be dd/mm/yyyy format
		,@DTINIZIO = GETDATE()
		
PRINT @DTFINE
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900