DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
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

 

 


Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE