Showing posts with label fields. Show all posts
Showing posts with label fields. Show all posts

Monday, March 26, 2012

Export data from 2 tables to a text file.

How do I export data from more than one table into a text file ?
Can I also export only certain fields in the table to the text file and have required format in the text file ?
Thanks & Regards,
SJcan "select * from table1,table2;" ?|||Hi,
No this alone will not be enough to export data to a text file, after searching thru the web i got this

SELECT a,b,a+b INTO OUTFILE "/tmp/result.text"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "\n"
FROM test_table;

but when i run this query it gives an error :-

"Incorrect syntax near '/tmp/result.text'."
maybe there is some problem with the path.... can someone help me on this ??|||some one ask can "select into..." before, seems no answer ;)|||I am still stuck with exporting data to a text file. I found some query, but I am having a problem in executing them in SQL query analyser

EXEC master..xp_cmdshell 'bcp "SELECT * FROM pubs..authors where state="'CA'" queryout authors.txt -U sa -P pwd -c'

when i run this in SQL query analyzer is it gives an err :-

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'CA'.

I've tried all kinds of combination like storing the string in a temp variable & then trying to run it, but it doesn't work...

--------------------------
From my local SQL server, when I try to run from the command prompt it works & the result is like this:-

C:\>bcp "SELECT * FROM pubs..authors where state='"CA"'" queryout authors.txt -U
sa -P quest -c

Starting copy...

15 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 30

But the problem is I cannot run this command for my remote SQL server machine, I have to execute the command from SQL query analyzer only

--------------------------

There must be some problem in string concatenation. Someone pl. help me...

Thanks
SJ|||Originally posted by sj_rao74
I am still stuck with exporting data to a text file. I found some query, but I am having a problem in executing them in SQL query analyser

EXEC master..xp_cmdshell 'bcp "SELECT * FROM pubs..authors where state="'CA'" queryout authors.txt -U sa -P pwd -c'

when i run this in SQL query analyzer is it gives an err :-

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'CA'.

I've tried all kinds of combination like storing the string in a temp variable & then trying to run it, but it doesn't work...

--------------------------
From my local SQL server, when I try to run from the command prompt it works & the result is like this:-

C:\>bcp "SELECT * FROM pubs..authors where state='"CA"'" queryout authors.txt -U
sa -P quest -c

Starting copy...

15 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 30

But the problem is I cannot run this command for my remote SQL server machine, I have to execute the command from SQL query analyzer only

--------------------------

There must be some problem in string concatenation. Someone pl. help me...

Thanks
SJ

Try this:

EXEC master..xp_cmdshell 'bcp "SELECT * FROM pubs..authors where state=''CA'' queryout authors.txt -U sa -P pwd -c'

before and after CA two simple quotes...|||Originally posted by ioana
Try this:

EXEC master..xp_cmdshell 'bcp "SELECT * FROM pubs..authors where state=''CA'' queryout authors.txt -U sa -P pwd -c'

before and after CA two simple quotes...

Sorry I forgot the last double quotes to close the select statement.
So, try this:
EXEC master..xp_cmdshell 'bcp "SELECT * FROM pubs..authors where state=''CA'' " queryout authors.txt -U sa -P pwd -c'sql

Friday, March 23, 2012

export as csv (tab delimited)

I try to configure RS to export report as csv with fields delimited by
tab.
I can set it to be any value (eg. semicolon) but can not do that with
tab.
Is it possible?what symbol should i put into FieldDelimiter setting fro RS to
recognize it as <<TAB>>?|||Has somebody managed to configure RS to do that?
Thanks in advance.|||I have tried everything and nothing :(
It seems like there is a bug in RS,
RS is trimming tab value in FieldDelimiter config|||Try adding the following line in your rsreportServer.config file this should
work.
<Extension Name="TAB"
Type="Microsoft.ReportingServices.Rendering.CsvRenderer.CsvReport,Microsoft.ReportingServices.CsvRendering" Extension
= ".txt" FieldDelimiter = "%09" />
"kamel" wrote:
> I have tried everything and nothing :(
> It seems like there is a bug in RS,
> RS is trimming tab value in FieldDelimiter config
>

Monday, March 12, 2012

Expert needed for this one( Select with sums on self joined table)

I have a services table that holds two types of records(new & old) and among the fields I have is Price. I need to add the total Price of all the new records and all total price of the old records. so I came up with this code.

SELECT Sum(tbl1.Price) AS OldCost, tbl1.ID, Sum(tbl2.Price) AS NewCost, tbl2.ID
FROM tblServices AS tbl1 INNER JOIN tblServices AS tbl2 ON tbl1.ClientID = tbl2.ClientID
WHERE ((tbl1.Type)="O") AND ((tbl2.Type)="N"))
GROUP BY tbl1.ClientID, tbl2.ClientID;

Now this almost works. except for the fact that it is doing some weird stuff by multiplying the totals times the number of records that it is pulling or something really close to that. I have never seen this before.

As a end Result I want three fields per record.
Total of New Services, Total of Old Services, and The client ID.

I have looked at it for 3 hrs and tryed everything I know to try. If I separate the query into two separate ones ( 1 for new and one for Old) it works perfectly but combinding them it just craps out.

Any Advice on what I am doing wrong.?
I really need some help...I am using access for my front end and I was playing around for kicks and I you can take two querys and make a nother one base doff those two, so that was my awnser.
Thanks

Friday, February 24, 2012

Exeption MSDE "Maximum length is 128"

I am using a SProc to update some fields in a database. The field I am updating is a comment field. When I pass the parameter by doing a Command.ExecuteNonQuery I get an exception that says my parameter is greater than 128. The field it is updating is a nvarchar with a length of 500. I found anarticle on Microsoft's website that is alluding to the fact that a "name" cannot be greater than 128. How else can I do an update of this size? I would like to use a SProc. I am still learning SQL 2000 and MSDE so this may be an easy fix. Here is the exception I am getting: "The identifier that starts with 'My data thats needs to be updated to the database' is too long. Maximum length is 128." -VBJBdpends on the variable that is holding the value. where is the comment coming from ? a textbox ?|||Yes the comment is comming from a textbox that is in a asp.net form.

ExecutionLog Fields

Is there a document that details what the fields in the ExecutionLog
represent. For example, what is the RowCount based on? Or how are the
TimeDataRetrieval, TimeProcessing & TimeRendering fields calculated?You may want to check this related thread for an explanation of execution
log times:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.sqlserver.reportingsvcs&mid=599418b6-d837-446b-b02b-26394c4a8a7b&sloc=en-us
The RowCount column shows the total number of rows read in _all_ datasets
during the report execution. This includes also dataset rows read for
query-based report parameters.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Propwash" <scott.tyree@.crossmark.com> wrote in message
news:1115137030.760735.158180@.o13g2000cwo.googlegroups.com...
> Is there a document that details what the fields in the ExecutionLog
> represent. For example, what is the RowCount based on? Or how are the
> TimeDataRetrieval, TimeProcessing & TimeRendering fields calculated?
>|||Ok, just to make sure I am fully understanding. If I have a SP that
joins three tables (A,B,C), then my RowCound will be the sum of tables
A, B & C plus the resulting recordset. Is this correct?|||No. The RowCount represents only the number of rows in the resulting record
set. If you join multiple table into one dataset inside the stored
procedure, it will not influence the RowCount.
However, if you use the record set in a report parameter and in the report,
you may say a higher count than if you only use it in the report.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Propwash" <scott.tyree@.crossmark.com> wrote in message
news:1115209799.601180.4530@.g14g2000cwa.googlegroups.com...
> Ok, just to make sure I am fully understanding. If I have a SP that
> joins three tables (A,B,C), then my RowCound will be the sum of tables
> A, B & C plus the resulting recordset. Is this correct?
>