Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it L'avatar di billy1
    Registrato dal
    Jun 2001
    Messaggi
    549

    SQL - problema conversione da smalldatetime a datetime

    ciao, ho un problema, sto cercando di importare un campo smalldatetime, in un campo datetime.

    mi viene errore, anche se cambio il formato della data...

    se uso cioe' 09-23-2006 oppure 23-09-2006 oppure 2006-09-23-mi da' sempre errore...

    come posso fare?

    questa come potete vedere sotto, e' l'istruzione che uso :

    convert(smalldatetime,'09-23-2006',110)


    codice:
    INSERT INTO news (recn, datam, on_line, id_scat, news_breve, news_meta_description, titolo, img_s_path, img_b_path, img_big_link, img_b2_path, img_b3_path, importata_automaticamente, importata_automaticamente_data) VALUES (284, convert(smalldatetime,'09-23-2006',110), '1', 39, '', 'Tissot Orologi Official Timekeeper of Nascar. Tissot sigla una partnership con l`Associazione Nazionale di Corse.', 'Tissot Orologi Official Timekeeper of Nascar', '/storeimgs/T90_4_496_82_small.jpg', '', '', '/storeimgs/149586ss_sm2_small.jpg', '/storeimgs/fam_PRS516_NASCAR_small.jpg', 'yes', '19/11/2010 15.26.18') 
    Microsoft OLE DB Provider for ODBC Drivers error '80040e07' 
    
    [Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. 
    
    /IMPORTAZIONE/importa_news.asp, line 249

    Inoltre, se invece non utilizzo l'istruzione INSERT INTO, ma apro un recordset in ASP e inserisco, dopo un po' di item mi viene fuori un errore differente e cioe' :

    codice:
    Microsoft Cursor Engine error '80004005' 
    Data provider or other service returned an E_FAIL status.
    In questo caso la data che metto e' nel formato :
    codice:
    2006-09-22 00:00:00
    Il fumo fa male a te e agli altri.
    Rispettate chi non vuole respirare il fumo passivo.

  2. #2
    vediamo un po' di codice?

  3. #3
    Utente di HTML.it L'avatar di billy1
    Registrato dal
    Jun 2001
    Messaggi
    549

    ecco il codice

    codice:
    datam = "23/09/2006"  ' PER ESEMPIO, MA NEL DATABASE VALE :
    23/09/2006 00:00:00
    
    qualsiasi valore metto come datam, da' sempre errore...
    
    datam_elaborato = mssqlDate(datam)
    
    str_insert = str_insert & "INSERT INTO news (recn, datam, on_line, id_scat, news_breve, news_meta_description, titolo, img_s_path, img_b_path, img_big_link, img_b2_path, img_b3_path, importata_automaticamente, importata_automaticamente_data) "
    
    str_insert = str_insert & "VALUES ("&recn&", convert(datetime,'"& datam_elaborato &"',110), '"&on_line&"', "&id_scat&", '"&news_breve&"', '"&news_meta_description&"', '"&titolo&"', '"&img_s_path&"', '"&img_b_path&"', '"&img_big_link&"', '"&img_b2_path&"', '"&img_b3_path&"', 'yes', '"&dataoggi&"') "
    e la funzione per la data:

    codice:
    function mssqlDate(strData)
    	dim strGiorno
    	dim strMese
    	dim strAnno
    	dim strOra
    	dim strMinuti
    	dim strSecondi
    	
    	strgiorno = day(strData)
    	if Len(strGiorno) = 1 then
    		strGiorno = "0" & strGiorno
    	end if
    	
    	strMese = Month(strData)
    	if Len(strMese) = 1 then
    		strMese = "0" & strMese
    	end if
    	
    	strAnno = Year(strData)
    	
    	strOra = Hour(strData)
    	if Len(strOra) = 1 then
    		strOra = "0" & strOra
    	end if
    	
    	strMinuti = Minute(strData)
    	if Len(strMinuti) = 1 then
    		strMinuti = "0" & strMinuti
    	end if
    	
    	strSecondi = Second(strData)
    	if Len(strSecondi) = 1 then
    		strSecondi = "0" & strSecondi
    	end if
    		
    	
    	' anno-mese-giorno
    	mssqlDate = strAnno & "-" & strMese & "-" & strGiorno & " " & strOra & ":" & strMinuti & ":" & strSecondi
    		
    	
    	
    End function

    SE INVECE DI INSERT INTO, USO IL RECORDSET, l'ERRORE e' IL SEGUENTE :

    dopo una venitna di record importati, appare :

    codice:
    Microsoft Cursor Engine error '80004005'   
    Data provider or other service returned an E_FAIL status.
    Il fumo fa male a te e agli altri.
    Rispettate chi non vuole respirare il fumo passivo.

  4. #4
    visto che tu già elabori la data, penso che la convert non serva

  5. #5
    Utente di HTML.it L'avatar di billy1
    Registrato dal
    Jun 2001
    Messaggi
    549

    ok

    ok ma mi da sempre errore...

    il campo del DATABASE di origine e' SMALLDATETIME, il campo del DATABASE di destinazione e' DATETIME

    ma anche se nella tabella del database di destinazione, io il campo lo metto identico a SMALLDATETIME, da' sempre errore...

    se invece poi di usare INSERT INTO, uso il recordset, mi viene fuori un errore stranissimo, anche se forzo a mano il campo datam = NULL

    ecco l'errore:
    codice:
    Microsoft Cursor Engine error '80004005'    
    Data provider or other service returned an E_FAIL status.
    qualccuno riesce ad aiutarmi per favore?
    Il fumo fa male a te e agli altri.
    Rispettate chi non vuole respirare il fumo passivo.

  6. #6
    fa' vedere l'istruzione senza convert

  7. #7
    Utente di HTML.it L'avatar di billy1
    Registrato dal
    Jun 2001
    Messaggi
    549

    istruzione sena convert

    Originariamente inviato da optime
    fa' vedere l'istruzione senza convert
    codice:
    str_insert = str_insert & "INSERT INTO news (recn, datam, on_line, id_scat, news_breve, news_meta_description, titolo, img_s_path, img_b_path, img_big_link, img_b2_path, img_b3_path, importata_automaticamente, importata_automaticamente_data) "
    
    str_insert = str_insert & "VALUES ("&recn&", '"& datam_elaborato &"', '"&on_line&"', "&id_scat&", '"&news_breve&"', '"&news_meta_description&"', '"&titolo&"', '"&img_s_path&"', '"&img_b_path&"', '"&img_big_link&"', '"&img_b2_path&"', '"&img_b3_path&"', 'yes', '"&dataoggi&"') "
    Il fumo fa male a te e agli altri.
    Rispettate chi non vuole respirare il fumo passivo.

  8. #8
    ----------------------------------------------------
    impariamo a fare un po' di debug

    *subito* dopo la composizione della stringa SQL metti

    Response.Write "maGGica SQL...: " & str_insert
    Response.Flush

    poi posta quello che viene a video
    ----------------------------------------------------

  9. #9
    Utente di HTML.it L'avatar di billy1
    Registrato dal
    Jun 2001
    Messaggi
    549
    so ke veniva una cosa del genere, nel campo datam :

    codice:
    INSERT INTO news (recn, datam, on_line, id_scat, news_breve, news_meta_description, titolo, img_s_path, img_b_path, img_big_link, img_b2_path, img_b3_path, importata_automaticamente, importata_automaticamente_data) "
    
    
    VALUES (22, '2006-09-23', 1, 31, 'testo testo', 'aaaaaa', 'bbbbb', '', '', '', '', '', 'yes', '19/11/2010 22.53.00')
    Il fumo fa male a te e agli altri.
    Rispettate chi non vuole respirare il fumo passivo.

  10. #10
    non è che l'errore te lo dà su importata_automaticamente_data?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.