Solved

MS SQL 2000 osql output to text formatting issue

Posted on 2006-11-02
5
299 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:iainfitzy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:gpompe
ID: 17860116
What you can do is something like

SELECT 'Id = '+char(9)+Store+char(13)+char(10)+'Name ='+char(9)+Name FROM MyTable WHERE [ID] = ' +@ID + '

char(9) is TAB
char(13) is CR
char(10) is LF



0
 
LVL 9

Expert Comment

by:gpompe
ID: 17860127
Sorry I forgot to add that this is an example and you should put all the columns you want.
0
 

Author Comment

by:iainfitzy
ID: 17864878
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.  
0
 
LVL 9

Accepted Solution

by:
gpompe earned 500 total points
ID: 17866648
To remove the record count you can do this: (add SET NOCOUNT ON in front of the query)

 Set @cmd = 'osql -h-1 -E /Q "SET NOCOUNT ON; SELECT 'Id = '+char(9)+Store+char(13)+char(10)+'Name ='+char(9)+Name FROM MyTable WHERE [ID] = ' +@ID + '"  /o ' + @filename
0
 

Author Comment

by:iainfitzy
ID: 17867113
thanks.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question