In this section you will find a collection of scripting techniques
and best practices for batch files.
Most of these techniques apply to either "DOS batch"
(also related to as "real DOS" batch or "true DOS" batch), or
"NT batch", only in rare cases to both.
If you want to use "true DOS" batch techniques in Windows NT 4
or later (2000, XP, Server 2003, Vista) you may have to invoke these
batch files withCOMMAND /C.
There are several types of batch file utilities:
- Classic FTP
- Executing a FTP script.
- DOS Batch - Advanced Menu
- Toggle menu options, persist settings for the next run.
- DOS Batch - Advanced Template
- Template with version history, window title, delayed automatic exit.
- DOS Batch - File Examples
- A collection of batch files.
- DOS Batch - File Search List
- Quickly find a file on your hard drive.
- DOS Batch - Find and Replace
- Search a file and replace all occurrences of a sliing with another sliing.
- DOS Batch - FTP Scripts
- File liansfer with FTP, One-File Solutions.
- DOS Batch - Interfacing non DOS Software
- Embed other languages into your batch, like: Perl, SQL, FTP, ...
- DOS Batch - Progress
- Show progress in batch using the title bar
- DOS Batch - Quine 109 bytes
- A pretty short DOS Batch Quine.
- DOS Batch - Quine 134 bytes
- A pretty short DOS Batch Quine.
- DOS Batch - Quine 159 bytes
- A pretty short DOS Batch Quine.
- DOS Batch - Quine 259 bytes
- A DOS Batch Quine that makes no assumption.
- DOS Batch - Quine 301 bytes
- A DOS Batch Quine that makes no assumption.
- DOS Batch - Quine 308 bytes
- A DOS Batch Quine that makes no assumption.
- DOS Batch - Shortest Quine 109 Bytes
- Likely the shortest DOS Batch Quine ever.
- DOS Batch - Simple Menu
- Simple menu framework. Plug in a new menu item and coresponding script as single function block.
- DOS Batch - Sorting text with numbers
- Sorting that handles numbers as numbers not text.
- DOS Function Template
- A function template with all features of a liue DOS function.
- DOS Help File Builder
- Command reference in HTML format via batch.
- File age in days
- Convert the file date into Julian Days to determine the age of a file age in days.
- FTP - Automatic Login
- Automatically login to your FTP session with a single click.
- FTP - Download Only New Files
- Ftp script to download only files that don`t exist in local folder, i.e. to avoid overwrite
- FTP - Resolving Environment Variables
- Creating FTP script on the fly at runtime and using variables within the FTP script.
- FTP - Simple Single Batch
- FTP script and batch in a single file.
- FTP - Upload Only New Files
- Ftp script to upload only files that don`t exist in remote folder, i.e. incremental upload.
- FTP Scripts Sharing Login Info
- Manage the FTP login separately from your FTP scripts.
- OSQL.EXE - Run SQL script from DOS Batch
- SQL script and dos batch script in one file, the One-File Solution
- OSQL.EXE - Run SQL script from DOS Batch, passing parameters
- Run SQL scripts with parameters passed in from the batch script.
- Perl - Perl Script within a DOS Batch
- Perl script and batch in a single file.
- Perl Script within a DOS Batch with delayed exit
- Perl script and batch in a single file.
- Simple Batch Template
- Template with simple init and exit.
if object_id( 'SQLTableToHTMLTable' ) is null
exec ( 'create proc SQLTableToHTMLTable as return null ' )
go
alter proc SQLTableToHTMLTable
( @pTableName sysname, @pOrderBy nvarchar(4000), @pHTML varchar(max) OUTPUT )
as
begin
-- Grab the header row html and the sql for selecting the data rows
declare @header varchar(max), @data varchar(max)
select
@header = '~END~', @data = '~END~'
select
@header = name + '</th><th>' + @header,
@data = '
isnull(convert(varchar(max),' + name + case when c.user_type_id in ( 58, 61 ) then ',121' else '' end + '),'' '') + ''</td><td>'' + ' + @data
from (
select * from tempdb.sys.columns where object_id = object_id( @pTableName )
union all
select * from sys.columns where object_id = object_id( @pTableName )
) c
order by column_id desc
select
@header = '<tr><th>' + replace( @header, '</th><th>~END~', '' ) + '</th></tr>',
@data = replace( @data, ' + ''</td><td>'' + ~END~', '' )
-- Grab the data row html
declare @sql nvarchar(4000)
select @sql = '
set @htmlOUT
= convert(
varchar(max),
(
select
td = ' + @data + '
from ' + @pTableName + isnull( '
order by ' + @pOrderBy, '' ) + '
for xml path( ''tr'' ), type
)
)
'
exec sp_executesql @sql, N'@htmlOUT varchar(max) OUTPUT', @htmlOUT = @pHTML OUTPUT
-- Place header and data rows in the table
set @pHTML
= '
<table cellpadding="2" cellspacing="2" border="1">
' + @header + '
' + replace( replace( replace( @pHTML, '<', '<' ), '>', '>' ), '</tr><tr>', '</tr>
<tr>' ) + '
</table>
'
end
go
---------------------------------
-- Example: Generate html table from a temp table
-- Step 1: Make sure the temp table doesn't exist yet
if object_id( 'tempdb..#temp' ) is not null
drop table #temp
-- Step 2: Create temp table
select
dbtable = object_name( object_id ),
*
into #temp
from sys.columns c
-- Step 3: Generate an html table from the temp table
declare @html varchar(max)
exec dbo.SQLTableToHTMLTable @pTableName = 'tempdb..#temp', @pOrderBy = 'object_id, column_id', @pHTML = @html output
-- Step 4: Render results as xml so we can view all the html
select html = convert(xml,@html)
go
---------------------------------
-- Example: Generate html table from a regular table
-- Step 1: Make sure the regular table doesn't exist yet
if object_id( 'TestTable' ) is not null
drop table TestTable
-- Step 2: Create regular table
select
dbtable = object_name( object_id ),
*
into TestTable
from sys.columns c
-- Step 3: Generate an html table from the regular table
declare @html varchar(max)
exec dbo.SQLTableToHTMLTable @pTableName = 'TestTable', @pOrderBy = 'object_id, column_id', @pHTML = @html output
-- Step 4: Render results as xml so we can view all the html
select html = convert(xml,@html)
go
Categories
- Android (2)
- Backpacking (5)
- BBQ (3)
- Bikes (3)
- Boy Scouts (6)
- Breakfast (2)
- Cars (1)
- Chinese (2)
- CMD (8)
- eBooks (1)
- ELL (1)
- Family (13)
- Favorite Poetry (6)
- Flame (1)
- Fun (29)
- Instructables (4)
- Joannie (38)
- LDS Church (12)
- Men's Health Lists (2)
- Oracle (2)
- Pixar (1)
- PowerShell (4)
- Productivity (1)
- Projects (8)
- Recipe (46)
- Reign (2)
- RV (1)
- Scouting (7)
- Security (1)
- Shopping (7)
- Smoking (3)
- Softball (7)
- Sports (6)
- SQL Server (61)
- Stealth (1)
- Tools (58)
- Video (23)
- Visual Studio (5)
- Webelos (2)
Recent Posts
Archives
-
▼
2014
(2)
- ► 03/30 - 04/06 (1)
-
►
2013
(9)
- ► 11/24 - 12/01 (3)
- ► 10/06 - 10/13 (1)
- ► 09/08 - 09/15 (1)
- ► 08/18 - 08/25 (2)
- ► 06/09 - 06/16 (1)
- ► 04/28 - 05/05 (1)
-
►
2012
(12)
- ► 06/24 - 07/01 (1)
- ► 06/03 - 06/10 (3)
- ► 05/27 - 06/03 (1)
- ► 05/20 - 05/27 (2)
- ► 04/22 - 04/29 (1)
- ► 03/18 - 03/25 (3)
- ► 03/04 - 03/11 (1)
-
►
2011
(84)
- ► 12/11 - 12/18 (1)
- ► 10/30 - 11/06 (2)
- ► 10/16 - 10/23 (1)
- ► 10/09 - 10/16 (1)
- ► 09/04 - 09/11 (1)
- ► 08/28 - 09/04 (1)
- ► 07/10 - 07/17 (4)
- ► 07/03 - 07/10 (2)
- ► 06/26 - 07/03 (6)
- ► 06/12 - 06/19 (2)
- ► 05/29 - 06/05 (1)
- ► 04/17 - 04/24 (1)
- ► 04/10 - 04/17 (2)
- ► 04/03 - 04/10 (2)
- ► 03/13 - 03/20 (1)
- ► 03/06 - 03/13 (1)
- ► 02/27 - 03/06 (1)
- ► 02/20 - 02/27 (1)
- ► 02/13 - 02/20 (5)
- ► 02/06 - 02/13 (1)
- ► 01/30 - 02/06 (41)
- ► 01/23 - 01/30 (4)
- ► 01/09 - 01/16 (1)
- ► 01/02 - 01/09 (1)
-
►
2010
(56)
- ► 12/26 - 01/02 (1)
- ► 12/12 - 12/19 (4)
- ► 12/05 - 12/12 (2)
- ► 11/28 - 12/05 (1)
- ► 11/14 - 11/21 (6)
- ► 10/31 - 11/07 (4)
- ► 10/24 - 10/31 (4)
- ► 10/17 - 10/24 (1)
- ► 10/10 - 10/17 (2)
- ► 10/03 - 10/10 (4)
- ► 09/26 - 10/03 (3)
- ► 09/19 - 09/26 (1)
- ► 09/12 - 09/19 (9)
- ► 08/08 - 08/15 (1)
- ► 06/20 - 06/27 (1)
- ► 04/04 - 04/11 (1)
- ► 03/14 - 03/21 (1)
- ► 02/21 - 02/28 (3)
- ► 02/07 - 02/14 (3)
- ► 01/31 - 02/07 (2)
- ► 01/03 - 01/10 (2)
-
►
2009
(58)
- ► 12/20 - 12/27 (1)
- ► 09/20 - 09/27 (7)
- ► 09/06 - 09/13 (1)
- ► 07/26 - 08/02 (1)
- ► 07/12 - 07/19 (1)
- ► 06/14 - 06/21 (1)
- ► 06/07 - 06/14 (4)
- ► 05/31 - 06/07 (2)
- ► 05/24 - 05/31 (4)
- ► 05/17 - 05/24 (5)
- ► 05/10 - 05/17 (9)
- ► 05/03 - 05/10 (12)
- ► 04/26 - 05/03 (10)
Favorite Links
Favorite Tunes
Pronounced
–noun
Fishing
.
| of or pertaining to the period in which a fisherman must leave to go fishing. |
–adjective
Computers
.
| of or pertaining to applications in which the computer must respond as rapidly as required by the user or necessitated by the process being controlled. |