Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQLEXEC - INSERT INTO syntax question
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00599449
Message ID:
00599472
Views:
22
>Thanks Sergey. I didn't think it would be that simple.
>
>>>Now, I want to do the same thing with datetime and numeric fields. How would I handle inserting records with those data types using SQLEXEC?
>>The datetime value in SQL Server is represented by a character string.
...
>>strSQL = strSQL + Transform(lnNumber) + ", "
>>strSQL = strSQL + "'" + DTOC(ldDate) + "', "
>>strSQL = strSQL + "'" + TTOC(ltDatetime) + "', "
>>...
>>
Al,
It's not. < s >

The SQL Server ODBC driver has a property called AutoTranslate. This proeprty determines if SQL Server will translate character expressions into the appropriate data type if they don't match. For example, if the field in question is a date and the character string passed in matches the date format then it will be translated. The default for this property is Yes (things will be translated). However, if this is set to No in the ODBC entry or the connection string then your code will fail.

A better approach, IMO, is to use the T-SQL function CONVERT() to explicitly convert your character string to the required date type. Ex.
set textmerge on
text to strSQL noshow
   Insert into tblTest(cText1, cText2, nNumber1, tDatetime1) Values(
      '<< lcText >>','<< lcText1 >>',<< lnNumber >>,
      convert(datetime,'<< year(ltdt) >>/<< month(ltdt) >>/<< day(ltdt) >> << hour(ltdt) >>:<< minute(ltdt) >>:<< sec(ltdt) >>',120)
endtext
(remove spaces before and after << >>)

Style 120 equates to yyyy/mm/dd hh/mm/ss (24Hr clock).

Also, in VFP 7, you can use the new TEXT TO Variable option. This makes programming SQL statements a lot easier because you don't have to worry about multiple delimiters ('"]) inside the string.

HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform