Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to pass an empty Date to SmallDatetime in SQL
Message
From
11/11/2003 07:49:54
Peter Wagner
Point Informática Ltda.
Limeira, Brazil
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00848564
Message ID:
00848649
Views:
17
Jozef,
Yes the column allows NULL values, but the error message is still there.
I dont know why it doesnt work.

Peter

>Hi Peter!
>Your idea of changing empty dates to NULL should work.
>Check if your datetime column in SQLServer table allows NULL values.
>
>
>>I have to upgrade a Database from a DBF to SQL Server where some tables structures were changed.
>>
>>In a scan..endscan I'm trying to build a string with the values from the VFP tables and then call a SP
>>to insert the values in SQL for each record.
>>In a function that builds the string for each record of the table and later calls a SP sending the string with the values.
>>All works fine but when I have empty Dates I replace the value with NULL, but when I execute the SP using SQLEXEC(), I get an error message telling the Date parameter was not suplied.
>>Any Ideia how to send empty Dates to SQL SERVER so it doesnt stores 01/01/1900 in SQL SmallDatetime.
>>
>>Thanks in advance.
>>
>>Peter
>>
>>
>>&& x_campos = AFIELDS(aCampos)
>>
>>FUNCTION Monta_String_SQL  && sample
>>LPARAMETERS x_campos
>>PUBLIC cSQL
>>cSQL = ''
>>FOR nCount = 2 TO x_campos			&& N° of fields of the table
>>	cNome_campo = aCampos[nCount,1]	&& Name of field
>>	cDado = EVALUATE(aCampos[nCount,1])	&& Value of the field
>>	aTipo = aCampos[nCount,2]		&& Type of field
>>	aTamanho = aCampos[nCount,3]	&& Size of field
>>	aCasasDec = aCampos[nCount,4]	&& Decimals...
>>.
>>.
>>	IF aTipo = "N" OR aTipo = "Y"
>>		cDado = STR(cDado,aTamanho,aCasasDec)
>>	ENDIF
>>
>>	IF aTipo = "B"
>>		IF aCasasDec > 0
>>			cDado = STR(cDado,aTamanho,aCasas)
>>		ELSE
>>			cDado = STR(cDado)
>>		ENDIF
>>	ENDIF
>>.
>>.
>>* Problem Here !
>>	IF aTipo = "D"
>>		IF EMPTY(cDado)	&& p/ campo sem data ficar sem data no SQL
>>			cDado = 'NULL'
>>		ELSE
>>			cData = DTOC(cDado)
>>			cDado = cData
>>		ENDIF
>>	ENDIF
>>
>>	cSQL = cSQL + "'" + cDado + "'"+ ","
>>
>>ENDFOR
>>cSQL = SUBSTR(cSQL,1,LEN(cSQL)-1)	&& removes the last ','
>>
>>
>>
>>
>>
>>cSQLString = "EXECUTE SPA_INS_Table_x " + cSQL
>>IF !SQLExec(nID, cSQLString)>= 1
>> =AERROR(mERRO)
>> ?mERRO(1,3)
>> ?mERRO(1,5)
>>ENDIF
>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform