|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
2 quickies......
2 quick questions for you:
1) Can you use SQL Query Analyser to output selected data from a query to a text file located locally? A little example would be great! 2) I want to use a query to select every 10th record from a table/query, is this possible? If so whats the basic T-SQL for it? Thanks a lot, Ben |
|
#2
|
|||
|
|||
|
Hopefully this can help you
Code:
CREATE PROCEDURE sp_AppendToFile(@FileName varchar(255), @Text1 varchar(255)) AS DECLARE @FS int, @OLEResult int, @FileID int EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObject', @FS OUT IF @OLEResult <> 0 PRINT 'Scripting.FileSystemObject' --Open a file execute @OLEResult = sp_OAMethod @FS, 'OpenTextFile', @FileID OUT, @FileName, 8, 1 IF @OLEResult <> 0 PRINT 'OpenTextFile' --Write Text1 execute @OLEResult = sp_OAMethod @FileID, 'WriteLine', Null, @Text1 IF @OLEResult <> 0 PRINT 'WriteLine' EXECUTE @OLEResult = sp_OADestroy @FileID EXECUTE @OLEResult = sp_OADestroy @FS http://www.motobit.com/tips/detpg_SQLWrFile.htm As far as every 10th record, you want to only return the 10th record or only write out the 10th record to the file but still return all records or what? |
|
#3
|
|||
|
|||
|
I would like to be able to only return every 10th record. By every 10th record i mean this:
one of the columns in the table is messagetime which is a datetime data type. So, i would like to return every 10th record based on this column. Hope this is clearer ![]() Cheers Ben |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > 2 quickies...... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|