Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


help with SQLCMD


help with SQLCMD

Author
Message
AppSup_dba
AppSup_dba
SSC Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 Visits: 716
Hi ,

I am trying to use SQLCMD to run a SQL Script. The script is of type.

Begin tran

Delete .....

Insert .....

Commit tran

The output captured doesnt show the proper output. Only rows affected by the DELETE statement is captured. Rows affected by the insert statement is not captured.

My SQLCMD statement looks like....

master.dbo.xp_cmdshell 'sqlcmd -SABC -d DEF -u -i "G:\fct_t.sql" -o "G:\fct_t.txt"'

Please help!!!

Cheers
OTF
OTF
Old Hand
Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)

Group: General Forum Members
Points: 316 Visits: 4128
AppSup_dba (8/24/2012)
Hi ,

I am trying to use SQLCMD to run a SQL Script. The script is of type.

Begin tran

Delete .....

Insert .....

Commit tran

The output captured doesnt show the proper output. Only rows affected by the DELETE statement is captured. Rows affected by the insert statement is not captured.

My SQLCMD statement looks like....

master.dbo.xp_cmdshell 'sqlcmd -SABC -d DEF -u -i "G:\fct_t.sql" -o "G:\fct_t.txt"'

Please help!!!


This is not very clear to me.

What output are you referring to? You would not typically expect any if you action an Insert or Delete unless you are reading from the Inserted/Deleted Tables?
AppSup_dba
AppSup_dba
SSC Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 Visits: 716
Thanks for looking into this... I will try to make it make clear....

Actual output:
Starting the Transaction.
Beginning to run the queries.

(0 rows affected)
Queries executed successfully.
Transaction committed successfully.



Expected output:
Starting the Transaction.
Beginning to run the queries.

(0 rows affected)
(1 rows affected)
(1 rows affected)
(1 rows affected)
Queries executed successfully.
Transaction committed successfully.

Cheers
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24200 Visits: 37964
Unfortunately, we can't see what you see. You haven't given us enough information to be able to help you. Based on what has been posted, I can't even give you a shot in the dark.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
OTF
OTF
Old Hand
Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)Old Hand (316 reputation)

Group: General Forum Members
Points: 316 Visits: 4128
AppSup_dba (8/24/2012)
Thanks for looking into this... I will try to make it make clear....

Actual output:
Starting the Transaction.
Beginning to run the queries.

(0 rows affected)
Queries executed successfully.
Transaction committed successfully.



Expected output:
Starting the Transaction.
Beginning to run the queries.



(0 rows affected)
(1 rows affected)
(1 rows affected)
(1 rows affected)
Queries executed successfully.
Transaction committed successfully.






Is there any conditional logic in there?

How did you determine that was the expected output?
You ran the query with another tool?
rVadim
rVadim
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1054 Visits: 2299
Lynn, OTF,
I think what OP is talking about is redirecting STDOUT to a file (specified by the -o switch). This supposed to capture all output produced by SQL statements in the input file (specified by -i) and write them to a file.

Ankur,
Are you sure there are no errors? Try to setup error log as well.

For Reference:
http://msdn.microsoft.com/en-us/library/ms162773(v=sql.105).aspx
markstains1
markstains1
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1
Even I tried this procedure. The link which you provided helped a lot. Thanks for providing the link.

Diseno grafico Zaragoza Paginas web Zaragoza
AppSup_dba
AppSup_dba
SSC Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 Visits: 716
In hurry to get my issue resolved i think i didnt provide enough information. My bad. I will try to make thing more clear now and provide scripts so that you can recreate the scenario.

My table structure:
CREATE TABLE [dbo].[test_t](
[ser] [nvarchar](100) NULL,
[exp_date] [date] NULL
) ON [PRIMARY]

SQL query that i intend to run:
DELETE FROM dbo.test_t WHERE ser = 'cd5546';
INSERT INTO dbo.test_t VALUES ('ab3546','2012-04-19')
INSERT INTO dbo.test_t VALUES ('ab4546','2012-04-19')
INSERT INTO dbo.test_t VALUES ('cd5546','2012-04-19')

When in run this query from MS, i get the following output(As expected):
(0 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)

When i run this query using SQLCMD in below syntax, after saving the sql query as C:\SQL\SQLQuery2.sql

master.dbo.xp_cmdshell 'sqlcmd -Sserver -d database -W -i "C:\SQL\SQLQuery2.sql" -o "C:\SQL\Output\SQLQuery2.sql"'

The output file that gets created as C:\SQL\Output\SQLQuery2.sql contains only below text.

(0 rows affected)


The number of rows affected by the Insert statements doesnt get captured. Actually only the output of first SQL statement is captured.

Though i tested that if i run my statements in batches, i get desired results. But i dont understand the behavior in above scripts.

I can provide any more info as required. Thanks people for your help... I great appreciate your support.

Cheers
AppSup_dba
AppSup_dba
SSC Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 Visits: 716
I will be happy to provide any more information in this regard....

Cheers
Sergiy
Sergiy
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5834 Visits: 11405
Did you check if the records are actually inserted by SQLCMD run?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search