Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

SQLCMD -o or >> file

$
0
0

Hello My first at this forum :-)

I’m struggling here :

 

I want to save my sqlcmd output to a file file.txt

I want to do this in 2 steps.

Step 1: Header

set @squery='sqlcmd -d DK_HISTORY  -f 65001 -h -1 -W -E -Q "exec GetSetup_Header"'

set @cmd=@squery+' -o C:\TEMP\txt.txt'

                     

execmaster.dbo.xp_cmdshell@cmd

set @squery=''

OUTPUT :

ENERGIDATA;;;30-04-2015 18:33;;; ;;; Brugeradresse;Beskrivelse;Bygning;Værdi

This is good i can see the ”æ”

STEP 2: DATA part

FETCHNEXTFROM export_cursorINTO @sFilename, @DESCRIPT, @DESCRIPT1, @sPoint1

                     

WHILE@@FETCH_STATUS= 0

BEGIN

set @squery='sqlcmd -d DK_HISTORY -h -1 -W -E -Q "exec gethistdata '''+ @sFilename+'.'+ @sPoint1 + ';'+ @DESCRIPT +';'+ @DESCRIPT1+';'+'''"'

set @cmd=@squery+' >> C:\TEMP\txt.

execmaster.dbo.xp_cmdshell@cmd

                    

FETCHNEXTFROM export_cursorINTO @sFilename,@DESCRIPT,@DESCRIPT1, @sPoint1

END

 

OUTPUT:

K02_000_RT;Rumtemperatur;Byg 100; K02_000_RT;Temp Indblsning;Byg 101;

Not soo good I see � but in database it is “æ”

Can anyone guide me to a solution ?

Thanks in advance

Mic



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>