datetime century date into pad dynamic cursor money percent sp job isnumeric isdate over update
SQLUSA.com
SQL 2008 GRAND SLAM ON 49 CD
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL Server Training SQL 2005 Scripts SQL 2008 Articles
SQL JOBS News Format Developer
How to look at the head of any table with SQLCMD?

Save the following SQL Server SQLCMD script in a designated folder as "selecttable.sql":

USE AdventureWorks

GO

SELECT TOP 100 *

FROM $(TableName)

ORDER BY 1

GO

 

Execute the following T-SQL script in Query Editor or the content of @CmdString at the command line starting with SQLCMD to see the head (TOP 100 rows) of Person.Contact and Sales.SalesOrderHeader tables:

DECLARE  @CmdString CHAR(2000)

 

SET @CmdString = 'sqlcmd -v TableName ="Person.Contact" -i

e:\data\script\selecttable.sql -S"ServerName"'

PRINT  @CmdString -- test & debug

EXEC xp_cmdshell   @CmdString

 

SET @CmdString = 'sqlcmd -v TableName ="Sales.SalesOrderHeader" -i

e:\data\script\selecttable.sql -S"ServerName"'

 

EXEC xp_cmdshell   @CmdString

 

/* Partial results

 

SalesOrderID      RevisionNumber    OrderDate

43659             1                 2001-07-01 00:00:00.000

43660             1                 2001-07-01 00:00:00.000

43661             1                 2001-07-01 00:00:00.000

43662             1                 2001-07-01 00:00:00.000

43663             1                 2001-07-01 00:00:00.000

*/

Execute a stored procedure with parameters via SQLCMD:

DECLARE  @CmdString VARCHAR(2000)

 

SET @CmdString = 'sqlcmd  -S"YOURSERVER" -Q"EXECUTE [AdventureWorks2008].[dbo].[uspGetBillOfMaterials] 800, ''20040401''"'

 

PRINT  @CmdString -- test & debug

 

EXEC xp_cmdshell   @CmdString

 

 


Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
Microsoft SQL Server 2012 Training Videos at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Accounting
Administrative
Advertising
Arts
Architecture
Banking
Business Intelligence
Career Jobs
Celebrity
Computer
Consulting
Customer Service
Education
Engineering
Entertainment
Entry Level
Executive
Federal
Finance
Government
Hardware
Healthcare
Hospital
Human Resources
Information Technology
Insurance
Internet
Job Openings
Laboratory
Law Enforcement
Legal
Logistics
Manufacturing
Marketing
Medical
Military
Nursing
Pharmaceutical
Physician
Public Relations
Publishing
Real Estate
Restaurant
Retail
Sales
Social Media
Software
SQL Database
Telecomm
Therapist
Training
Transportation
Truck Driver
Travel
Web
Work from Home

FREE SS SQL / BI OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011 Microsoft Community Contributor 2012

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts

JOIN US ON TWITTER

Copyright 2005-2012, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.