Alaska Software Inc. - Create a csv file with the sql sentence SELECT .... INTO OUTFILE (For Microsoft SqlExpress)
Username: Password:
AuthorTopic: Create a csv file with the sql sentence SELECT .... INTO OUTFILE (For Microsoft SqlExpress)
César Calvo Create a csv file with the sql sentence SELECT .... INTO OUTFILE (For Microsoft SqlExpress)
on Sat, 12 Nov 2016 22:21:55 +0100
I am trying to create a csv file with SqlExpress and the sql sentence SELECT 
.... INTO OUTFILE but there is something wrong.
Could anybody say me if this is correct or other instruction for get it?

PROCEDURE PRUEBA()
LOCAL cConStr, oConStr, oCon1, cSql, oStmt

   oConStr := dsConnectionString():new(";")

   oConStr:AddEntry("Driver","SQL Server")
   oConStr:AddEntry("Server","CESARCC\SQLEXPRESS")
   oConStr:AddEntry("UID","cesarcc")
   oConStr:AddEntry("PWD","1234ccc")
   oConStr:AddEntry("Database","DBFTID")
   oConStr:AddEntry("WSID","WorkStationID")
   oConStr:AddEntry("Trusted_Connection","Yes")

   cConStr := oConStr:GetConnectString()

   oCon1 := SQLConnection():new()

   IF !oCon1:driverConnect(nil, cConStr)
      MsgBox("Unable to connect to server!")
      RETURN
      ELSE

      IF FExists("D:\ACREEDORES.csv")
         FErase("D:\ACREEDORES.csv")
      ENDIF

      cSql := "SELECT * FROM ACREEDORES INTO OUTFILE 'd:\acreedores.csv' 
FIELDS TERMINATED BY ',' LINES TERMINATED BY ',';"

      oStmt := oCon1:NewStatement()
      oStmt:DisplayErrors := .t.
      oStmt:SQLString := cSql
      oStmt:Execute()
      oStmt:destroy()

      oCon1:destroy()

   ENDIF

RETURN

Thanks.
César.
Matej JuracRe: Create a csv file with the sql sentence SELECT .... INTO OUTFILE (For Microsoft SqlExpress)
on Tue, 15 Nov 2016 08:43:17 +0100
This (it is from MySQL) will not go with Microsoft SQL via SQL commands.

It is only possible in Sql Server Management Studio to export resoult into
external file.

The code would only work in Windows versions of MySql/MariaDB (local) not at
all with Linux OS.

It is also bad practice - you cannot expect to hare write priviliges on
database servers, except locals.

To export data, you should really write own code to read fields/records and
write them into coresponding output file.





César Calvo <ccalvoc@telefonica.net> wrote in message
news:a889f16$5daf2925$75a90@news.alaska-software.com...
>I am trying to create a csv file with SqlExpress and the sql sentence SELECT 
>.... INTO OUTFILE but there is something wrong.
>Could anybody say me if this is correct or other instruction for get it?
>
>PROCEDURE PRUEBA()
>LOCAL cConStr, oConStr, oCon1, cSql, oStmt
>
>   oConStr := dsConnectionString():new(";")
>
>   oConStr:AddEntry("Driver","SQL Server")
>   oConStr:AddEntry("Server","CESARCC\SQLEXPRESS")
>   oConStr:AddEntry("UID","cesarcc")
>   oConStr:AddEntry("PWD","1234ccc")
>   oConStr:AddEntry("Database","DBFTID")
>   oConStr:AddEntry("WSID","WorkStationID")
>   oConStr:AddEntry("Trusted_Connection","Yes")
>
>   cConStr := oConStr:GetConnectString()
>
>   oCon1 := SQLConnection():new()
>
>   IF !oCon1:driverConnect(nil, cConStr)
>      MsgBox("Unable to connect to server!")
>      RETURN
>      ELSE
>
>      IF FExists("D:\ACREEDORES.csv")
>         FErase("D:\ACREEDORES.csv")
>      ENDIF
>
>      cSql := "SELECT * FROM ACREEDORES INTO OUTFILE 'd:\acreedores.csv' 
>FIELDS TERMINATED BY ',' LINES TERMINATED BY ',';"
>
>      oStmt := oCon1:NewStatement()
>      oStmt:DisplayErrors := .t.
>      oStmt:SQLString := cSql
>      oStmt:Execute()
>      oStmt:destroy()
>
>      oCon1:destroy()
>
>   ENDIF
>
>RETURN
>
>Thanks.
>César.