|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Sunday, January 06, 2008 9:01 PM
Points: 33,
Visits: 89
|
|
| execution of a query in sql server express and saving the result/output in a doc /pdf file.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Sunday, February 28, 2010 3:31 PM
Points: 399,
Visits: 452
|
|
Anu,
If you are using SSMSE then you can do the following 1.) Open SSMSE, connect to SQL express 2.) Press ctrl+shift+f 3.) enter the query and execute , then a window will pop-up to save the results to a file
If you are using command prompt (i.e sqlcmd) 1.) sqlcmd -Sservername -E -Q"Your query" -o"output file path"
Pls note, change the servername,query and output path and use appropriate authentication to connect to the server and then press enter.
You can't directly convert the output to a pdf instead you can save it to a txt file and the convert to pdf.
Regards..Vidhya Sagar SQL-Articles
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Sunday, January 06, 2008 9:01 PM
Points: 33,
Visits: 89
|
|
hi Mr. Vidya Sagar, Thanks for ur reply . But i tried the one what is give by u but i dint get the result. can u be more detailed about that .
Actual requirement is that i want to get the result of a trigger when the particular table is effected to be oppened in .net application for that first iam trying to save the result in the text file the i can try for .net application.
waiting for the reply thanks in advance.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Thursday, February 11, 2010 2:17 AM
Points: 52,
Visits: 35
|
|
Anu,
You can write the query output to an output file like .txt or .doc etc. by using OSQL or SQLCMD utilities. These are command line utilities used to execute sql queries at command prompt. Try the below one and let me know.
c:/> SQLCMD -E(trusted connection) –S(servername) -i(iputfile) -o(outputfile)
eg: c:/> sqlcmd -E -Sxx\abc -id:/query.txt -oresult.txt
In the above example -i(query.txt) should consists of the query you want to execute and the result will be copied to -o(result.txt) file. Instead of using -i(inputfile) you can also write the query here. For more options of SQLCMD or OSQL check at command prompt by giving the name. eg: c:/>osql ( provides the entire options used in osql ) Same process can be followed for OSQL utility also. If any error occurs, please post the error.
Hope this may help u.
Cheers, Naveen
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Sunday, January 06, 2008 9:01 PM
Points: 33,
Visits: 89
|
|
Hi Naveen, Thank You for ur reply . But what i want is not that.
My actual requiremtent is to save the result of the query to a text file not from command promt but it must be from sql server express itself.
Iam having a table on which i created a trigger.if any record is inserted in that table my trigger will fire , through this trigger i have to open the text file and want to save the result in that text file. this must be done when the trigger is fired.
If u can plzz help me out .
Thank you , Anujahanvi S.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 7:39 AM
Points: 2,121,
Visits: 2,534
|
|
You must first create the textfile with the column headers in it. Below is an example of openrowset.
Use AdventureWorks go
INSERT OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Text;Database=C:\',test#txt) --query goes here SELECT FirstName FROM Person.Contact Where ContactID < 50
My blog: http://jahaines.blogspot.com
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, July 11, 2008 7:33 AM
Points: 1,
Visits: 6
|
|
Hi Naveen,
Can you please help me in this issue..
How to use the OSQL -b ..
i didnot got any answer from goole..
so please help .
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 12:54 PM
Points: 1,523,
Visits: 1,198
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, February 04, 2009 7:34 AM
Points: 129,
Visits: 130
|
|
Hi Anu,
Please follow the instructions below.
1) open the SQL server, 2) Connect to the particular DB 3) Opne the Query Analyzer inSQL 2000 and in 2005 Click on New query tab, 4) Write your query into query pann, 5) Press Ctrl + T (This is for result in .txt) 6) Execute your query, 7) You will find your query result in txt format. 8) select all (Ctrl + A) 9) Press Ctrl + C for copy 10) Open notepad file and paste (Ctrl + V) and 11) save it in .txt or .sql for SQL query format.
Manoj MCP,MCTS
Manoj
MCP, MCTS (GDBA/EDA)
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, December 22, 2009 9:26 PM
Points: 1,
Visits: 14
|
|
| I like that there is always another way of doing things in SQL. and that people are happy to SHARE their knowledge. thanks!
|
|
|
|