Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

help with SQLCMD Expand / Collapse
Author
Message
Posted Friday, August 24, 2012 5:27 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 3:12 AM
Points: 210, Visits: 643
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
Post #1349587
Posted Friday, August 24, 2012 8:45 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 31, 2013 3:44 AM
Points: 314, Visits: 4,128
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?
Post #1349714
Posted Friday, August 24, 2012 8:50 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 3:12 AM
Points: 210, Visits: 643
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
Post #1349719
Posted Friday, August 24, 2012 9:45 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:34 PM
Points: 20,676, Visits: 32,269
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.



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)
Post #1349772
Posted Friday, August 24, 2012 9:46 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 31, 2013 3:44 AM
Points: 314, Visits: 4,128
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?
Post #1349773
Posted Friday, August 24, 2012 11:21 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, September 12, 2014 2:16 PM
Points: 990, Visits: 2,223
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
Post #1350003
Posted Saturday, August 25, 2012 12:38 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, August 25, 2012 12:27 AM
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
Post #1350018
Posted Monday, August 27, 2012 3:51 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 3:12 AM
Points: 210, Visits: 643
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
Post #1350289
Posted Tuesday, August 28, 2012 1:38 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 3:12 AM
Points: 210, Visits: 643
I will be happy to provide any more information in this regard....

Cheers
Post #1351220
Posted Wednesday, August 29, 2012 2:53 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Thursday, September 18, 2014 11:10 PM
Points: 4,573, Visits: 8,351
Did you check if the records are actually inserted by SQLCMD run?
Post #1351478
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse