Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
siprem
Starting Member
6 Posts |
Posted - 2008-12-15 : 10:30:27
|
| Hi All, I am new to sql server and need help in reading the last line of a flat file. This last line contains the line count of the entire file.I managed to find the number of lines in the file but am not able to get the last line:Ths code which returns the number of lines is as below:SET nocount ONDECLARE @FileName varchar(8000)DECLARE @NumLines int DECLARE @XPCmdString varchar(8000) SET @FileName = 'F:\Import\RawData\DataBase_Txt\1.txt'SET @XPCmdString = 'find /V /C " " ' + @FileName CREATE TABLE #XPOutput (XPLineOut varchar(1000))INSERT INTO #XPOutput EXEC master..xp_cmdshell @XPCmdStringDELETE FROM #XPOutput WHERE XPLineOut IS NULL SELECT @NumLines = SUBSTRING (XPLineOut, 12 + len(@FileName) + 2, 1000) FROM #XPOutputSELECT * FROM #XPOutputSELECT @NumLinesDrop table #XPOutputPlease help me |
|
|
darkdusky
Aged Yak Warrior
591 Posts |
Posted - 2008-12-15 : 11:48:39
|
| SET nocount ONDECLARE @FileName varchar(8000)DECLARE @NumLines int DECLARE @XPCmdString varchar(8000)SET @FileName = 'C:\temp\test.txt'SET @XPCmdString = 'type ' + @FileNameCREATE TABLE #XPOutput (RowID int identity, XPLineOut varchar(1000))INSERT INTO #XPOutput exec master.dbo.xp_cmdshell @XPCmdStringDELETE FROM #XPOutput WHERE XPLineOut IS NULLSELECT @NumLines = (Select count(*) from #XPOutput)SELECT * FROM #XPOutputSELECT @NumLinesSelect *from #XPOutputwhere RowID = @NumLines -1 Drop table #XPOutput |
 |
|
|
|
|
|