Précédent   Forum des professionnels en informatique > Bases de données > MS SQL-Server > Développement
Développement Forum d'entraide sur le Transact-SQL, le CLR, les procédures stockées, les triggers, les requêtes SQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 05/04/2011, 09h30   #1
Invité de passage
 
Inscription : avril 2008
Messages : 65
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 65
Points : 3
Points : 3
Par défaut Ecrire dans un fichier avec SQL SERVER

Bonjour;

je voudrais écrire dans un fichier text ou excel en programmant une SP dans sql server.

j'ai aucune idée comment ça marche.
quelqu'un peut il m'aider?

merci d'avance
xavier81 est déconnecté   Envoyer un message privé Réponse avec citation 01
Vieux 05/04/2011, 10h50   #2
Rédacteur/Modérateur

 
Avatar de SQLpro
 
Homme Frédéric BROUARD
Expert SGBDR & SQL
Inscription : mai 2002
Messages : 10 953
Détails du profil
Informations personnelles :
Nom : Homme Frédéric BROUARD
Localisation : France

Informations professionnelles :
Activité : Expert SGBDR & SQL
Secteur : Conseil

Informations forums :
Inscription : mai 2002
Messages : 10 953
Points : 17 773
Points : 17 773
Vous n'avez visiblement fait aucune recherche !!!

http://blog.developpez.com/sqlpro/p8...texte-via-sql/

A +
__________________
Frédéric Brouard - SQLpro - ARCHITECTE DE DONNÉES - expert SGBDR et langage SQL
Site sur les SGBD relationnels et le langage SQL: http://sqlpro.developpez.com/
Expert Microsoft SQL Server - M.V.P. (Most valuable Professional) MS Corp.
Blog SQL, SQL Server, modélisation données : http://blog.developpez.com/sqlpro
http://www.sqlspot.com : modélisation, conseils, audit, optimisation, formation
* * * * * Enseignant CNAM PACA - ISEN Toulon - CESI Aix en Provence * * * * *
SQLpro est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 05/04/2011, 11h50   #3
Responsable SQL Server

 
Avatar de mikedavem
 
Homme David BARBARIN
Expert SQL Server
Inscription : août 2005
Messages : 3 723
Détails du profil
Informations personnelles :
Nom : Homme David BARBARIN
Localisation : France, Haute Savoie (Rhône Alpes)

Informations professionnelles :
Activité : Expert SQL Server
Secteur : Conseil

Informations forums :
Inscription : août 2005
Messages : 3 723
Points : 6 844
Points : 6 844
Bonjour,

En sus de la solution donnée par SQLPro, vous pouvez vous orienter vers du SQL CLR si vous possédez une version 2005 ou plus

++
mikedavem est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/04/2011, 12h52   #4
Rédacteur/Modérateur

 
Avatar de WOLO Laurent
 
Homme Laurent WOLO
Architecte de base de données
Inscription : mars 2003
Messages : 2 696
Détails du profil
Informations personnelles :
Nom : Homme Laurent WOLO
Âge : 35
Localisation : Congo-Brazzaville

Informations professionnelles :
Activité : Architecte de base de données
Secteur : Finance

Informations forums :
Inscription : mars 2003
Messages : 2 696
Points : 3 917
Points : 3 917
Envoyer un message via Yahoo à WOLO Laurent
Vous avez aussi ceci:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
CREATE PROCEDURE PROC_WriteStringToFile
 (
@String Varchar(8000) ,
@Path VARCHAR(255),
@Filename VARCHAR(100)
 
)
AS
DECLARE  @objFileSystem int
        ,@objTextStream int,
		@objErrorObject int,
		@strErrorMessage Varchar(1000),
	    @Command varchar(1000),
	    @hr int,
		@fileAndPath varchar(80)
 
SET nocount ON
 
SELECT @strErrorMessage='opening the File System Object'
EXECUTE @hr = sp_OACreate  'Scripting.FileSystemObject' , @objFileSystem OUT
 
SELECT @FileAndPath=@path+'\'+@filename
if @HR=0 Select @objErrorObject=@objFileSystem , @strErrorMessage='Creating file "'+@FileAndPath+'"'
if @HR=0 execute @hr = sp_OAMethod   @objFileSystem   , 'CreateTextFile'
	, @objTextStream OUT, @FileAndPath,2,True
 
if @HR=0 Select @objErrorObject=@objTextStream, 
	@strErrorMessage='writing TO the file "'+@FileAndPath+'"'
if @HR=0 execute @hr = sp_OAMethod  @objTextStream, 'WRITE', Null, @String
 
if @HR=0 Select @objErrorObject=@objTextStream, @strErrorMessage='closing the file "'+@FileAndPath+'"'
if @HR=0 execute @hr = sp_OAMethod  @objTextStream, 'Close'
 
if @hr<>0
	begin
	Declare 
		@Source varchar(255),
		@Description Varchar(255),
		@Helpfile Varchar(255),
		@HelpID int
 
	EXECUTE sp_OAGetErrorInfo  @objErrorObject, 
		@source output,@Description output,@Helpfile output,@HelpID output
	Select @strErrorMessage='Error whilst '
			+coalesce(@strErrorMessage,'doing something')
			+', '+coalesce(@Description,'')
	raiserror (@strErrorMessage,16,1)
	end
EXECUTE  sp_OADestroy @objTextStream
EXECUTE sp_OADestroy @objTextStream
__________________

Découvrez la FAQ de MS SQL Server.
La chance accorde ses faveurs aux esprits avertis !
WOLO Laurent est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h25.


 
 
 
 
Partenaires

Hébergement Web