iainfitzy
asked on
MS SQL 2000 osql output to text formatting issue
Hi,
I'm currently running the following line in my stored procedure:
Set @cmd = 'osql -h-1 -E /Q "SELECT * FROM MyTable WHERE [ID] = ' +@ID + ' " /o ' + @filename
and the following output is produced:
3.0 myStore union Street Dundee NULL UK G12 5TY 300.0 20.0 9.0 Y Y 1.0 ? Y 1.0 ? Y 3.0 ? N 2.0 2.0 N 0.0 ? (1 row affected)
This pulls results from the following DB:
[Id] [float] NULL ,
[Name] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Address Line1] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Address Line 2] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Address Line 3] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Town] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Postcode] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
etc
What i really need is some way to better format the output from osql - so that something like the following is displayed:
Id = Value from Store field
Name = Value from Name field
Address Line1 = Value from Address 1 field
Address Line 2 = Value from Address 2 field
etc
Is this possible to do this with osql as i am attempting? Or is there another way to create formattable files on the fly from a stored proedure in sql2000?
Many thanks,
Iain
I'm currently running the following line in my stored procedure:
Set @cmd = 'osql -h-1 -E /Q "SELECT * FROM MyTable WHERE [ID] = ' +@ID + ' " /o ' + @filename
and the following output is produced:
3.0 myStore union Street Dundee NULL UK G12 5TY 300.0 20.0 9.0 Y Y 1.0 ? Y 1.0 ? Y 3.0 ? N 2.0 2.0 N 0.0 ? (1 row affected)
This pulls results from the following DB:
[Id] [float] NULL ,
[Name] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Address Line1] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Address Line 2] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Address Line 3] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Town] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[Postcode] [nvarchar] (255) COLLATE Latin1_General_CI_AS NULL ,
etc
What i really need is some way to better format the output from osql - so that something like the following is displayed:
Id = Value from Store field
Name = Value from Name field
Address Line1 = Value from Address 1 field
Address Line 2 = Value from Address 2 field
etc
Is this possible to do this with osql as i am attempting? Or is there another way to create formattable files on the fly from a stored proedure in sql2000?
Many thanks,
Iain
Sorry I forgot to add that this is an example and you should put all the columns you want.
ASKER
Cheers, i'll try out this method. One quick point though, is it possible to remove the '(1 row affected)' from the end of the file that i create? i've used SET NOCOUNT ON but this doesnt appear to be making a difference.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks.
SELECT 'Id = '+char(9)+Store+char(13)+c
char(9) is TAB
char(13) is CR
char(10) is LF