Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Server DATE fields show as numbers in VFP
Message
From
31/10/2016 16:09:09
 
General information
Forum:
Microsoft SQL Server
Category:
Database management
Environment versions
SQL Server:
SQL Server 2012
OS:
Windows Server 2008 R2
Miscellaneous
Thread ID:
01642533
Message ID:
01642555
Views:
41
Likes (1)
>Hi
>When i connect to a SQL Server DB, either with the Database Explorer or through sqlstringconnect, all the DATE fields figure in VFP as numbers.
>For instance, March 18, 2005 comes as 9051840
>What did i do wrong?
>
>Thanks
>Jaime

You can check on the effect that ODBC driver / SQL data types have on VFP data types with this (adapt at your will, if you need to check on other data types):
LOCAL MSSQLStmt AS String
CLEAR

SET VARCHARMAPPING ON

* set your server and credentials (as strings)
#DEFINE SERVER_NAME	""
#DEFINE USER_LOGIN	""
#DEFINE USER_PWD		""

TEXT TO m.MSSQLStmt NOSHOW
SELECT CAST(GETDATE() AS date) as t_date, 
	CAST(GETDATE() AS datetime) as t_datetime,
	CAST(GETDATE() AS datetime2) as t_datetime2,
	CAST(GETDATE() AS smalldatetime) AS t_smalldatetime,
	CAST(GETDATE() AS time) AS t_time,
	CAST(GETDATE() AS datetimeoffset) AS t_datetimeoffset,
	CAST(1.1 AS float) AS t_float, 
	CAST(1.1 AS real) AS t_real,
	CAST(1.1 AS numeric(10,2)) AS t_numeric10_2,
	CAST(1 AS bit) AS t_bit,
	CAST('Žižek' AS char(10)) AS t_char10,
	CAST('Žižek' AS varchar(10)) AS t_varchar10,
	CAST('Žižek' AS text) AS t_text,
	CAST('Žižek' AS char(256)) AS t_char256,
	CAST('Žižek' AS varchar(256)) AS t_varchar256,
	CAST('Žižek' AS nchar(10)) AS t_nchar10,
	CAST('Žižek' AS nvarchar(10)) AS t_nvarchar10,
	CAST('Žižek' AS ntext) AS t_ntext,
	CAST('Žižek' AS nchar(256)) AS t_nchar256,
	CAST('Žižek' AS nvarchar(256)) AS t_nvarchar256,
	CAST('Žižek' AS nvarchar(max)) AS t_nvarcharmax
ENDTEXT

MSSQL2VFP_Types("SQL Server", m.MSSQLStmt)
MSSQL2VFP_Types("SQL Server Native Client 10.0", m.MSSQLStmt)
MSSQL2VFP_Types("SQL Server Native Client 11.0", m.MSSQLStmt)

PROCEDURE MSSQL2VFP_Types (Driver AS String, SQLStmt AS String)
LOCAL ODBC AS Integer
LOCAL Cols AS Integer

m.ODBC = SQLSTRINGCONNECT("Driver={" + m.Driver + "};Server=" + SERVER_NAME + ";" + ;
									"Uid=" + USER_LOGIN + ";Pwd=" + USER_PWD)

IF m.ODBC != -1
	?
	? m.Driver FONT "Arial",14 STYLE "B"
	SQLEXEC(m.ODBC, m.SQLStmt, "curCols")
	FOR m.Cols = 1 TO FCOUNT("curCols")
		? PADR(SUBSTR(FIELD(m.Cols, "curCols", 0), 3), 20, ".")
		?? TYPE(FIELD(m.Cols, "curCols"))
		?? " = [" + TRANSFORM(EVALUATE(FIELD(m.Cols, "curCols"))) + "]"
	ENDFOR
	SQLDISCONNECT(m.ODBC)
	
	WAIT WINDOW "Click to continue..."
ENDIF

ENDPROC
Are you really sure about the number 9051840 as a representation of {^2005-03-18}?
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform