How to spool the result of an query into a file in sql 2000
Hi All,
I have an SQL query which iterates through number of times for checking on some conditions and will return results each time. I wants to save the results into an different xml file each time. I tried using below query:
exec xp_cmdshell 'bcp "use Mimsadaptorlogs; select top 10 * from log order by logdate" queryout "D:\cdr_cg.xml" -T -c -t,' ---> Its not working as expected.
I got the Below output:
NULL
Starting copy...
SQLState = 01000, NativeError = 5701
Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]Changed database context to 'MIMSAdaptorlogs'.
NULL
10 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 62
NULL
Could you anuone please suggest me on this.......
Thanks and Regards, Bala
You will need to write a client program to do this. SQL Server is not intended for writing files. People still do it by calling BCP through xp_cmdshell, but this is a dubious practice. Better is to write a CLR stored procedure for the task. However, you
are on SQL 2000, and the CLR support was added in SQL 2005. Furthermore, there is no XML type in SQL 2000, and the only way to generate XML is with the FOR XML clause. But this output is not well understood by BCP. Then I try: [code} bcp "SELECT * FROM Northwind..Customers
FOR XML RAW" queryout slask.bcp -c -T [/code] on SQL 2000, I get [code] 11 rows copied. [/code] which is complete hogwash, because there are 91 rows in that table, and the output should be a single XML document, and the output looks like this: [code] <row
CustomerID="ALFKI"... Bouchers" City="Marseil... tomerID="DUMON" Company... 0.32.21.21" Fax="40.32.... los Hern ndez" ContactT... n Steel" ContactTitle="... e" ContactTitle="Market... ="Salzburg" PostalCode=... " Phone="(21) 555-3412"... ty="Charleroi" PostalCo...
<row CustomerID="WARTH"... [/code] I have truncated the output on the right side, but the left side is authentic. It really is that bad.
Erland Sommarskog, SQL Server MVP, [email protected]
Similar Messages
-
Extracting the result of a query into a internal table
Hi,
Does anyone knows or have an idea how to extract the result of a query into a internal table, is there a function module or BAPI?
Thanks in advance,
CKSo then normally I would use a statment like:
IFunctionTemplate ftemplate = repository.getFunctionTemplate("<b>BAPI_SALESORDER_GETLIST</b>");
to call a particluar function, but I tried using
IFunctionTemplate ftemplate = repository.getFunctionTemplate("<b>BAPI_MDDATAPROVIDERBW_GETCATALOGS</b>");
and it did not seem to work. I also tried -
IFunctionTemplate ftemplate = repository.getFunctionTemplate("<b>MDDataProviderBW.GetCatalogs</b>");
How do I format the function?
Thanks
Paul -
Procedure to save the output of a query into excel file or flat file
Procedure to save the output of a query into excel file or flat file
I want to store the output of my query into a file and then export it from sql server management studio to a desired location using stored procedure.
I have run the query --
DECLARE @cmd VARCHAR(255)
SET @cmd = 'bcp "select * from dbo.test1" queryout "D:\testing2.xlsx;" -U "user-PC\user" -P "" -c '
Exec xp_cmdshell @cmd
error message--
SQLState = 28000, NativeError = 18456
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'user-PC\user'.
NULL
Goel.AmanHello,
-T:
Specifies that the bcp utility connects to SQL Server with a trusted connection using integrated security. The security credentials of the network user,
login_id, and password are not required. If
–T is not specified, you need to specify
–U and –P to successfully log in.
-U:
Specifies the login ID used to connect to SQL Server.
Note: When the bcp utility is connecting to SQL Server with a trusted connection using integrated security, use the
-T option (trusted connection) instead of the
user name and password combination
I would suggest you take a look at the following article:
bcp Utility: http://technet.microsoft.com/en-us/library/ms162802.aspx
A similar thread regarding this issue:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/b450937f-0ef5-427a-ae3b-115335c0d83c/bcp-connection-error-sqlstate-28000-nativeerror-18456?forum=sqldataaccess
Regards,
Elvis Long
TechNet Community Support -
How to write the output of a mapping into a file (OWB10.2
Hi
I am using Oracle 10.2.0.1 version of OWB.
the task is to write the output of a mapping into a File (Flat File).
Please help me out!
Regards
AbiHi,
Create the file format thru OWB and mention the location in OWB. Deploy the file and it will be ready to use for target load. Make sure the connection to the target loc is available.
Regards
Bharadwaj Hari -
How to supress the result in a query?
Hi Experts!
I have a query, and by default show results right / down.
How can I set in design-mode that dont show any result?
Thanks!Hi,
You mean to say that you want to suppress the result rows while creating the query itself.
Check these threads.
How to change default for Suppress Results Rows
Suppress results row by default when creating new queries?
Regards,
Rk. -
How to tokenize the result from a query
Hi,
I need some help in writing a query or stored procedure for the following scenario
select rname from emp where username='user200';
This query will return the result,as comma separated,in the format r100,r101,r102
Now,I have to write another query using the above result like below
select place from loc where rname in ('r100','r101','r102');
Basically,I need to break the string 'r100,r101,r102' into 3 tokens.Can someone help me write a stored procedure or query for this?
Thanks
Ravi.Ravi, Try this.
CREATE OR REPLACE procedure str_token
is
input_buffer varchar2(100);
var1 varchar2(10);
var2 varchar2(10);
var3 varchar2(10);
n1 number(4);
n2 number(4);
n3 number(4);
cursor c1 is
select place from loc1 where rname in (var1,var2,var3);
begin
select rname into input_buffer from emp1 where username='user200';
n1 := instr(input_buffer,',',1,1);
n2 := instr(input_buffer,',',1,2);
n3 := length(input_buffer) + 1 ;
select
substr(input_buffer,1,n1-1),
substr(input_buffer,n1+1,n2-n1-1),
substr(input_buffer,n2+1,n3-n2-1)
into var1, var2, var3
from dual;
for i in c1
loop
dbms_output.put_line('place:'||i.place);
end loop;
end;
Regs,
Karthik -
How to sum the result rows at query designer
Hi,
We want to sum the result rows which are at the end of the row by the help of query designer?So ,we directly see at analyzer
exp:
..A.jan...A.feb...B.may...B.jun...SumA...SumB....SumA+B
X..1............9..........6..............7........10.........13..........?????
Edited by: zarata on Oct 23, 2011 12:49 PM
Edited by: zarata on Oct 23, 2011 1:07 PMHi,
Could you please provide some more information.
if you have characteristics iobject whose values are (A, B etc) and calendar month in rows and then at column level you have key figures then if you have turn on the "Display Result Rows" property of both iobject in Bex as "Always" you can get the result. At the same time you can set "Display Overall result" property of the Query to get overall result.
Regards,
Pravin -
[JCOP Shell] how to get the result of a script into a variable ?
Hello all,
I have a jcsh script that swaps the Two nibbles of an hexadecimal number.
#swap.jcsh
X= 0xAB
R= $(/expr $(/expr ${X} << 4 ) + $(/expr ${X} >> 4 ) )
/echo 0x${R;h2} the value echoed is 0xBA, right.
now, I want to replace the X varibale by an argument variable ( ${1} ) and , instead of echoing the result, storing it into another varibale; example :
Y= swap 0x23this is not working. ;-(
Does anyone knows how to do it ? is there a "return" equivalent to put at the end of my "swap" script ?
mkdata are you there ? :)
KartagosThank you very much mkdata
I solve it temporarely by using a global Variable TEMP that will be used by scripts to store the result, then the caller script will simply read the value of this variable (old old school global variable method :) )
now I'm considering re-writing my libraries
I knew that there something "DEFUN" but i didn't find any help (when typing "help /error" it talks about something called "defun")
I think I should write to the JCOP Team to update their docs.
Regards
Khaled -
How to spool the null alias column names in sppol file
Hi,
I have to spool the data and having some issues.
SELECT DISTINCT a.market_name,a.market_code,*''as empid* from ssp2_pcat.markets a ;
in the above select sql I have created extra null column as empid
when I spool with tild dilimited I am not getting column name(empid) in spool file.
a.market_name||'~'||a.market_code||'~'||'''empid'
SSB ~25010~' empid
In the feed file it should be null. but the alias column is populted with empid
Can you please let me know what is wrong here?
Thanks,SELECT DISTINCT a.market_name,a.market_code,*''as empid* from ssp2_pcat.markets a ;
in the above select sql I have created extra null column as empid
when I spool with tild dilimited I am not getting column name(empid) in spool file.
a.market_name||'~'||a.market_code||'~'||'''empid'
SSB ~25010~' empid
In the feed file it should be null. but the alias column is populted with empid
Can you please let me know what is wrong here?
Thanks,Try this one
SELECT DISTINCT a.market_name||'`'||a.market_code as empid from ssp2_pcat.markets a ; -
Exporting the results of a query into excel
Hi,
Here's my code for exporting a cfm page into a spreadsheet:
<cfsetting enablecfoutputonly="Yes">
<cfcontent type="application/msexcel">
<cfheader name="Content - Disposition" value="filename=myReport.xls">
<cfquery name="getInfo" datasource="#dsn#">
SELECT id, fname, lname, orgname, email, phone, topic, synopsis, pdf, expertise, fiscal_year, date_added
FROM table
</cfquery>
<table border="1" cellspacing="1">
<tr>
<td>EFRI 2011 Submissions (Total Submissions: <cfoutput>#getInfo.recordcount#</cfoutput>)</td>
</tr>
<tr>
<td>Record Number:</td><td>Last Name</td><td>First Name</td><td>E-mail</td>
<td>Phone</td>
<td>Organization</td>
<td>Expertise</td>
</tr>
<cfoutput query="getInfo">
<tr>
<td>#currentRow#. #lname#</td>
<td>#fname#</td>
<td>#email#</td>
<td>#phone#</td>
<td>#orgname#</td>
<td>#expertise#</td>
</tr>
</cfoutput>
</table>
and here's the error that I'm getting. What is wrong with the code?
500
Corrupt form data: no leading boundary: != -----------------------------7d96c1140276
java.io.IOException: Corrupt form data: no leading boundary: != -----------------------------7d96c1140276
at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:174)
at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:93)
at coldfusion.filter.FormScope.fillMultipart(FormScope.java:136)
at coldfusion.filter.FusionContext.SymTab_initForRequest(FusionContext.java:428)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:33)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126)
at coldfusion.CfmServlet.service(CfmServlet.java:175)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:284)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)try this
<cfsetting showdebugoutput="false">
<cfcontent type="application/msexcel">
<cfheader name="Content-Disposition" value="attachment; filename=myReport.xls"> -
How to capture the output of another program into a File/String
I needed to capture the output of a dos program in an String/file I tried doing Runtime.getRuntime.exec("ipconfig /all >tmp.txt");
but still I am unable to capture the output frm the program which I would like to capture in a file or String.Can anyone helpWhen you use the Runtime.exec() method, it returns a Process object, that process object has access to the streams; stdout, stdin, and stderr of the application you just executed. what you'll want to monitor is the stdout or stderr streams using the
p.getInputStream() or p.getErrorStream(), where p = the process object returned via the Runtime.exe() method. -
How to execute a procedure depending on the result of a query?
Hello, I'm new in ODI.
I want to execute a procedure depending on the result of a query Oracle table.
We have a Oracle Table whit a column that contains two possibles values.
I want read the table, row by row, and depending on this value, execute a Procedure or execute another.
How can i do?what you need to do is
1. create a variable which "new_var2" which has the count of the number of rows you want to process. must be data type numeric.
2. copy "new_var2" to the package screen.
3. duplicate the "new_var2" on the package screen and evaluate the variable and test for "> 0" zero, call it "new_var2_E"
3. create a new odi variable "new_var1" with a refresh of "select field1 fom (select field1,rownum as rownumber from tablex) where rownumber = #new_var2" in the relevant schema and technology.
4. copy "new_var1" into your package (some where in the flow)
5. right click the "new_var1" variable in you package screen and you should get the option duplicate step (click on that)
6. select the the duplicate "new_var1" on the package screen and correct the the name to something meaning full to you "new_var1_E", also change the "type" to "evaluate variable" then you should see a "value" box. enter one of the values you want to test in the box (remember do not put in quotes ' )
7. now back on the package screen join the "new_var1" to the "new_var1_E" with an OK line
8 you now join "new_var2" to "new_var2_E" with OK
9 you join "new_var2_E" to "new_var1"
10. you then join the "new_var1_E" with an OK or a KO line to the relevant procedure.
12. you need to duplicate "new_var2" in the package screen one more time this time and call it "new_var2_D" set the type to evaluate and then select the increment of -1
13. the relevant procedure to "new_var2_D" with an OK
14. join the "new_var2_D" to the "new_var2_E" with an OK
15. this should close off the loop now the exit point is "new_var2_E" with a KO line to the next part of your process....
Basically you should end up with a loop on new_var2 decementing, and it is used to get a specific next record row from your table.
Hope this helps, sorry it is a little long winded..
Edited by: DavidGD on Feb 8, 2009 3:29 PM -
How to achieve the results by Query ??
Hello Guys,
I have couple tables which I need to join to get the result....This is what is in the tables...
CList Table
CID, Name
A, ABC
B,CDE
C,JFK
JList Table
JID, Name
1, Something
2, Another
3, Else
4, Should be something
JOb_2_Courses
JobID, CourseID
1,A
1,B
2,C
Employee Table
EID, Job_ID
1A, 1
2A,1
3B,1
2C,2
23D,3
CStatus Table
StatusID, Desc
1,Completed
2,Pending Approval
3,Declined
4,Scheduled
5,Register
Now user can only register the course which are related with their job....NO course else.....
When they register it is moved to temp_course_registration and then once completed to COURSE_HISTORY
For Example : So Employee : 1A will see two courses to register A and B...
Say he registers A....it makes an entry in temp_course_registration table with the course id, employeeid and date....
With further steps once that status is updated to '1'.....the course is deleted from temp_course_registration and is moved to course_history........
Now to show to the user...I need to include all my tables in the query and on the basis of status, show necessary things to the user....
Output :
Course_ID, Status.............
Say if they completed the course will come from course_history, if in the process will come from temp_course_registration.....if nothing is in the tables for the specific employee...this means status is '5' and they need to register everything...
Can someone let me know, how to achieve the results....
Thanks,
HarsimratHello
I'm off home now so I can't look at the query, but for future reference, if you want to improve your chances of getting help, you need to provide simple create table statements, and test data to go with it. I've done that with what you provided and hopefully someone else will be able to help. Also, you were asked if you could provide this in your other thread...
CREATE TABLE CList(CID varchar2(1), Name varchar2(3))
insert into clist values('A', 'ABC');
insert into clist values('B','CDE');
insert into clist values('C','JFK');
CREATE TABLE JList(JID number, Name varchar2(30))
insert into jlist values(1, 'Something');
insert into jlist values(2, 'Another');
insert into jlist values(3, 'Else');
insert into jlist values(4, 'Should be something');
CREATE TABLE JOb_2_Courses(JobID number, CourseID varchar2(1))
insert into job_2_courses VALUES(1,'A');
insert into job_2_courses VALUES(1,'B');
insert into job_2_courses VALUES(2,'C');
CREATE TABLE Employee (EID varchar2(3), Job_ID number)
INSERT INTO employee VALUES('1A', 1);
INSERT INTO employee VALUES('2A',1);
INSERT INTO employee VALUES('3B',1);
INSERT INTO employee VALUES('2C',2);
INSERT INTO employee VALUES('23D',3);
CREATE TABLE CStatus(StatusID number, Descr varchar2(30))
insert into cstatus values(1,'Completed');
insert into cstatus values(2,'Pending Approval');
insert into cstatus values(3,'Declined');
insert into cstatus values(4,'Scheduled');
insert into cstatus values(5,'Register');HTH
David -
How to use the result of a sql query for a max () function
Hi
I wrote a query on which i wrote
"select max(id) from users "
how can i use the returned value.
if i made the var name ="userid"
can it be userid.rows[0] or what.
thnx for any helpHi!
The result of this query will be the max ID of users' IDs.
Let say we have:
String sql="select max(users.id) from users";
Statement st = ctx.conn.createStatement();
ResultSet rs = st.executeQuery(sql);
rs.next();
So you can get the max Id in the following way:
int maxId=rs.getInt("id");
Regards,
Rossi -
Af:query - How to get the result rowsets
Hi,
I have a requirement where i need to search the db rows on and append the results the adf rich table on each search.
For this i am using af:query component. And trying to get the result rows for the named criteria.
String mexpr = "#{bindings.DestinDescVOCriteriaQuery.processQuery}";
processMethodExpression(mexpr, queryEvent, QueryEvent.class);
ViewCriteriaManager vcm = getDestinDescViewObj().getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria("DestinDescVOCriteria");
getDestinDescViewObj().applyViewCriteria(vc);
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
adfFacesContext.addPartialTarget(tblDestinDesc);
However on each click of search the rows searched in the previous attempt are not retained.
Can anyone let me know how to get the result from named criteria and append it the table?
Thanks
AjayCan anyone help?
Maybe you are looking for
-
How to change network settings
hello, so i just recently got my first macbook pro (yay me) and the day i was setting it up i was going through the start ups and all and when it came to the network connections i used a connection that is a guest connection for my home router and no
-
Error while passing date parameter to the XML data definition
Hi All, I have developed a BI publisher report using XML data definition & RTF template. This data definition contains a SQL query in it's CDATA section and runs as a concurrent program(without RDF) . We are looking to pass a date parameter to the SQ
-
No JRE version found in launch file for this system
Hi, I have an application which is launched by JWS. When we use JWS from 1.4, it runs fine. But JWS from 1.5.0_15 gives the error "No JRE version found in launch file for this system" In both the JWS(1.4 and 1.5.0_15)cases, we install JRE1.5.0_15 usi
-
Problem with closing other firefox windows when window in use has more than 1 tab open
If I have multiple firefox windows open, and the one that I am using has more than one tab open, when I try to close one of the windows that I am not using by hovering over the firefox icon on the taskbar, then clicking the cross on the other windows
-
I have an old version of PS with 4 licenses. I upgraded one of them to CS2 for free. Now I want to install the rest. How do I go about getting the serial #'s?