Showing posts with label csv. Show all posts
Showing posts with label csv. Show all posts

Friday, February 17, 2012

Extracting data to CSV file

How do you write a query in Query Analyzer that extracts data from a table
into a .CSV file. I need the data in that format in order to upload into an
old Sybase database. ThanksEither use BCP, or select the Query / Results to File option in QA, or
use DTS, or use OSQL with the output switch option. In principle you
can do these things from a script in QA but usually that's not
necessary. If you want to automate it then use SQL Agent or some other
process to invoke one of those methods.
David Portas
SQL Server MVP
--|||SELECT ColA + ',' + ColB + ',' + ColC FROM TableName
Or
Use DTS to export the table to a CSV file
Or
Use DTS to export the file directly to Sybase.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"ChrisB" wrote:

> How do you write a query in Query Analyzer that extracts data from a table
> into a .CSV file. I need the data in that format in order to upload into a
n
> old Sybase database. Thanks|||Hi
create table ww
(
col1 int,
col2 varchar(50),
col3 varchar (50)
)
insert into ww values (47,'ReadyShip','(503)888-999')
insert into ww values (48,'MyShipper','(503)1212-454')
insert into ww values (49,'ReadyShip','(45)888-999')
insert into ww values (50,'MyShipper','(545)1212-454')
bcp northwind.dbo.ww out d:\test1.txt -c -t, -SMyServ -Uuser -Ppass
exec master..xp_cmdshell 'BCP northwind..ww IN
d:\test1.txt -c -C850 -SMyServ -Uuser -Ppass'
"ChrisB" <ChrisB@.discussions.microsoft.com> wrote in message
news:923AF22E-DF46-4DDB-84BE-18FCAEBE09FF@.microsoft.com...
> How do you write a query in Query Analyzer that extracts data from a table
> into a .CSV file. I need the data in that format in order to upload into
an
> old Sybase database. Thanks|||The query requires nothing special. Just execute the query within Query
Analyzer with the results going to the grid. When you get the results back,
click the mouse in the grid and choose the menu option File.. Save As..
"ChrisB" <ChrisB@.discussions.microsoft.com> wrote in message
news:923AF22E-DF46-4DDB-84BE-18FCAEBE09FF@.microsoft.com...
> How do you write a query in Query Analyzer that extracts data from a table
> into a .CSV file. I need the data in that format in order to upload into
> an
> old Sybase database. Thanks

extracting csv string and using in NOTIN clause

Hi,
I'm trying to pass a stored proc a list of values in a comma seperated strin
g:
("3125,3126,3129...") The values represent an integer column in a table.
Then I want to use the string to exclude the values from a SELECT as in:
CREATE PROCEDURE myProc
@.transactionIDs varchar(255)
AS
SELECT TransactionID FROM SalesTransactions
WHERE TransactionID NOT IN (@.transactionIDs)
GO
SQL Server complains that it can't cast a varchar to an int
Any suggestions on how to do this?
Can someone provide an example?
ThanksWhile someone might suggest you use dynamic SQL for this, I
wouldn't. Instead, consider either this not-so efficient solution:
select TransactionID
from SalesTransactions
where
charindex(
',' + rtrim(TransactionID) + ',',
',' + @.transactionIDs + ','
) = 0
-- be sure @.transactionIDs has no spaces
or, for greater efficiency, the more involved solution
that uses a table-valued function to convert @.transactionIDs
into a table of id values:
http://groups.google.co.uk/groups?q...wierzbicki+kass
You can then write:
select TransactionID
from SalesTransactions
where TransactionID not in (
select Item from ListTable(@.transactionIDs)
)
Steve Kass
Drew University
Opa wrote:

>Hi,
>I'm trying to pass a stored proc a list of values in a comma seperated stri
ng:
>("3125,3126,3129...") The values represent an integer column in a table.
>Then I want to use the string to exclude the values from a SELECT as in:
>CREATE PROCEDURE myProc
> @.transactionIDs varchar(255)
>AS
>SELECT TransactionID FROM SalesTransactions
>WHERE TransactionID NOT IN (@.transactionIDs)
>GO
>SQL Server complains that it can't cast a varchar to an int
>
>Any suggestions on how to do this?
>Can someone provide an example?
>Thanks
>
>
>