RODBC: How to Retrieve a Column as Rownames?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

RODBC: How to Retrieve a Column as Rownames?

Markus Preisetanz
Dear Collegues,

 

when using sqlQuery from the package RODBC I always get a data frame with automatically generated rownames, even if:

*  the first column of the query is called rownames using "Select ... AS rownames, ... From ..."

*  and: the values from this column are unique

*  and: the values are inevitably forced to character data with e.g. " 'rn_' + CAST(xy AS NVARCHAR) "

 

It works with sqlFetch but I would have to define a view for every query. Does anybody know help?

 

SQL-Server: MS SQL 2000

 

 

___________________

Markus Preisetanz

Consultant

 

Client Vela GmbH

Albert-Roßhaupter-Str. 32

81369 München

fon:          +49 (0) 89 742 17-113

fax:          +49 (0) 89 742 17-150

mailto:[hidden email] <mailto:[hidden email]>



Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged infor...{{dropped}}


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: RODBC: How to Retrieve a Column as Rownames?

Brian Ripley
On Wed, 1 Feb 2006, Markus Preisetanz wrote:

> Dear Collegues,
>
> when using sqlQuery from the package RODBC I always get a data frame with automatically generated rownames, even if:
>
> *  the first column of the query is called rownames using "Select ... AS rownames, ... From ..."
>
> *  and: the values from this column are unique
>
> *  and: the values are inevitably forced to character data with e.g. " 'rn_' + CAST(xy AS NVARCHAR) "
>
> It works with sqlFetch but I would have to define a view for every
> query. Does anybody know help?

Well, you use ?sqlQuery to find out, as I just did.  What is so hard about
that?

This is documented feature of sqlFetch, and not mentioned at all as
supported by sqlQuery.  As sqlFetch is a wrapper for sqlQuery you can just
write your own wrapper based on it.

The (unacknowledged) maintainer of RODBC, and author of this feature.

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html