Voila je shouaiterais creer un fichier texte contenant des informations
suivante extraite d'une table
Comment faire pour creer un fichier avec un
nom unique a chaque fois : genre set @OutputFileName = 'c:\ooo_xxx.txt' avec
xxx un entier autoincrementé ???
j'utilise ces functions :
********************************
CREATE Function Func_Append_To_File
(
@FileName Varchar(255),
@TextToWrite Varchar(1024)
)
returns varchar(1)
begin
----- Set the delimiter characher (CHAR(9) is tab) and output file name here
set @Delimiter = CHAR(9)
set @OutputFileName = 'c:\ooo.txt'
-------------------
DECLARE curFileOutput CURSOR FORWARD_ONLY FOR
select
Cast ( IsNull(Product_Id,'') as VarChar(30)) + @Delimiter +
Cast ( IsNull(Pack_Id,'') as VarChar(30)) + @Delimiter +
N.Name + @Delimiter +
IsNull(N.Form,'') + @Delimiter +
IsNull(N.Strength,'') + @Delimiter +
IsNull(N.Flavour,'') + @Delimiter +
IsNull(D.Unit_Of_Issue,'') + @Delimiter +
Max(IsNull(Barcode,'')) + @Delimiter +
Cast ( IsNull(Qty_Issued,'') as VarChar(30)) + @Delimiter +
Cast ( IsNull(Issued_By,'') as VarChar(30))
As Data
from inserted Ii
join tbl_dispense_Item Di on (Di.Global_Script_Form_Id =
Ii.Global_Script_Form_Id) and (Di.Script_Item_Id = Ii.Script_Item_Id) and
(Di.Item_Number = Ii.Item_Number) and (Di.Repeat_Part = Ii.Repeat_Part)
join tbl_drug D on (Di.Drug_Id = D.Drug_Id)
join tbl_drug_name Dn on (Dn.Drug_Id = D.Drug_Id and Dn.Name_Type = 1)
join tbl_name N on (N.Name_Id = Dn.Name_Id)
left join tbl_barcode B on (B.Drug_Id = D.Drug_Id)
Group By
Product_Id,Pack_Id,N.Name,N.Form,N.Strength,N.Flavour,D.Unit_Of_Issue,Qty_Is
sued,Issued_By
OPEN curFileOutput FETCH NEXT FROM curFileOutput into @Data
----- Set the delimiter characher (CHAR(9) is tab) and output file name
here
set @Delimiter = CHAR(9) set @OutputFileName = 'c:ooo.txt' -------------------
DECLARE curFileOutput CURSOR FORWARD_ONLY FOR select Cast ( IsNull(Product_Id,'') as VarChar(30)) + @Delimiter + Cast ( IsNull(Pack_Id,'') as VarChar(30)) + @Delimiter + N.Name + @Delimiter + IsNull(N.Form,'') + @Delimiter + IsNull(N.Strength,'') + @Delimiter + IsNull(N.Flavour,'') + @Delimiter + IsNull(D.Unit_Of_Issue,'') + @Delimiter + Max(IsNull(Barcode,'')) + @Delimiter + Cast ( IsNull(Qty_Issued,'') as VarChar(30)) + @Delimiter + Cast ( IsNull(Issued_By,'') as VarChar(30)) As Data from inserted Ii join tbl_dispense_Item Di on (Di.Global_Script_Form_Id > Ii.Global_Script_Form_Id) and (Di.Script_Item_Id = Ii.Script_Item_Id) and (Di.Item_Number = Ii.Item_Number) and (Di.Repeat_Part = Ii.Repeat_Part) join tbl_drug D on (Di.Drug_Id = D.Drug_Id) join tbl_drug_name Dn on (Dn.Drug_Id = D.Drug_Id and Dn.Name_Type = 1) join tbl_name N on (N.Name_Id = Dn.Name_Id) left join tbl_barcode B on (B.Drug_Id = D.Drug_Id) Group By
Ton code devrait fonctionner sans problème
Le fichier est sur le serveur et pas sur ton poste
Bien cordialement
Med Bouchenafa
"Stephane Vander Clock" <svanderclock@yahoo.fr> a écrit dans le message de
news: e$YDPdq1DHA.1764@TK2MSFTNGP10.phx.gbl...
Bonjour,
Voila je shouaiterais creer un fichier texte contenant des informations
suivante extraite d'une table
Comment faire pour creer un fichier avec un
nom unique a chaque fois : genre set @OutputFileName = 'c:ooo_xxx.txt'
avec
xxx un entier autoincrementé ???
j'utilise ces functions :
********************************
CREATE Function Func_Append_To_File
(
@FileName Varchar(255),
@TextToWrite Varchar(1024)
)
returns varchar(1)
begin
----- Set the delimiter characher (CHAR(9) is tab) and output file name
here
set @Delimiter = CHAR(9)
set @OutputFileName = 'c:ooo.txt'
-------------------
DECLARE curFileOutput CURSOR FORWARD_ONLY FOR
select
Cast ( IsNull(Product_Id,'') as VarChar(30)) + @Delimiter +
Cast ( IsNull(Pack_Id,'') as VarChar(30)) + @Delimiter +
N.Name + @Delimiter +
IsNull(N.Form,'') + @Delimiter +
IsNull(N.Strength,'') + @Delimiter +
IsNull(N.Flavour,'') + @Delimiter +
IsNull(D.Unit_Of_Issue,'') + @Delimiter +
Max(IsNull(Barcode,'')) + @Delimiter +
Cast ( IsNull(Qty_Issued,'') as VarChar(30)) + @Delimiter +
Cast ( IsNull(Issued_By,'') as VarChar(30))
As Data
from inserted Ii
join tbl_dispense_Item Di on (Di.Global_Script_Form_Id > Ii.Global_Script_Form_Id) and (Di.Script_Item_Id = Ii.Script_Item_Id) and
(Di.Item_Number = Ii.Item_Number) and (Di.Repeat_Part = Ii.Repeat_Part)
join tbl_drug D on (Di.Drug_Id = D.Drug_Id)
join tbl_drug_name Dn on (Dn.Drug_Id = D.Drug_Id and Dn.Name_Type = 1)
join tbl_name N on (N.Name_Id = Dn.Name_Id)
left join tbl_barcode B on (B.Drug_Id = D.Drug_Id)
Group By
----- Set the delimiter characher (CHAR(9) is tab) and output file name
here
set @Delimiter = CHAR(9) set @OutputFileName = 'c:ooo.txt' -------------------
DECLARE curFileOutput CURSOR FORWARD_ONLY FOR select Cast ( IsNull(Product_Id,'') as VarChar(30)) + @Delimiter + Cast ( IsNull(Pack_Id,'') as VarChar(30)) + @Delimiter + N.Name + @Delimiter + IsNull(N.Form,'') + @Delimiter + IsNull(N.Strength,'') + @Delimiter + IsNull(N.Flavour,'') + @Delimiter + IsNull(D.Unit_Of_Issue,'') + @Delimiter + Max(IsNull(Barcode,'')) + @Delimiter + Cast ( IsNull(Qty_Issued,'') as VarChar(30)) + @Delimiter + Cast ( IsNull(Issued_By,'') as VarChar(30)) As Data from inserted Ii join tbl_dispense_Item Di on (Di.Global_Script_Form_Id > Ii.Global_Script_Form_Id) and (Di.Script_Item_Id = Ii.Script_Item_Id) and (Di.Item_Number = Ii.Item_Number) and (Di.Repeat_Part = Ii.Repeat_Part) join tbl_drug D on (Di.Drug_Id = D.Drug_Id) join tbl_drug_name Dn on (Dn.Drug_Id = D.Drug_Id and Dn.Name_Type = 1) join tbl_name N on (N.Name_Id = Dn.Name_Id) left join tbl_barcode B on (B.Drug_Id = D.Drug_Id) Group By