Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
help with SQLCMD
17 posts, Page 1 of 2
1
2
»»
help with SQLCMD
Rate Topic
Display Mode
Topic Options
Author
Message
AppSup_dba
AppSup_dba
Posted Friday, August 24, 2012 5:27 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:14 PM
Points: 125,
Visits: 498
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,
Ankur
Post #1349587
OTF
OTF
Posted Friday, August 24, 2012 8:45 AM
SSC Veteran
Group: General Forum Members
Last Login: Today @ 10:20 AM
Points: 254,
Visits: 3,713
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
AppSup_dba
AppSup_dba
Posted Friday, August 24, 2012 8:50 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:14 PM
Points: 125,
Visits: 498
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,
Ankur
Post #1349719
Lynn Pettis
Lynn Pettis
Posted Friday, August 24, 2012 9:45 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 9:18 PM
Points: 21,596,
Visits: 27,409
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
OTF
OTF
Posted Friday, August 24, 2012 9:46 AM
SSC Veteran
Group: General Forum Members
Last Login: Today @ 10:20 AM
Points: 254,
Visits: 3,713
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
rVadim
rVadim
Posted Friday, August 24, 2012 11:21 PM
SSC Eights!
Group: General Forum Members
Last Login: Yesterday @ 1:36 PM
Points: 887,
Visits: 2,062
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
markstains1
markstains1
Posted Saturday, August 25, 2012 12:38 AM
Forum 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
AppSup_dba
AppSup_dba
Posted Monday, August 27, 2012 3:51 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:14 PM
Points: 125,
Visits: 498
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,
Ankur
Post #1350289
AppSup_dba
AppSup_dba
Posted Tuesday, August 28, 2012 1:38 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:14 PM
Points: 125,
Visits: 498
I will be happy to provide any more information in this regard....
Cheers,
Ankur
Post #1351220
Sergiy
Sergiy
Posted Wednesday, August 29, 2012 2:53 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 5:01 PM
Points: 4,540,
Visits: 8,184
Did you check if the records are actually inserted by SQLCMD run?
Post #1351478
« Prev Topic
|
Next Topic »
17 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.