I like some help on the syntax for a query: I have a table that has about 50
columns. I need to have 30 of the columns in a query using a select
statement. Since many of the columns are prefixed 'cc', I'd like to use a
wildcard, instead of typing out each column name. Is this possible? For
example, select cc* from table, or select cc% from table.
Thanks
steve.No. Either select * from , or specify column names. If this is a repeated
work, create a view with the 30 columns and you can select * from the view.
"molsonexpert" <imdrunk@.work.ca> wrote in message
news:utISCBGkEHA.3664@.TK2MSFTNGP12.phx.gbl...
> I like some help on the syntax for a query: I have a table that has about
50
> columns. I need to have 30 of the columns in a query using a select
> statement. Since many of the columns are prefixed 'cc', I'd like to use a
> wildcard, instead of typing out each column name. Is this possible? For
> example, select cc* from table, or select cc% from table.
> Thanks
> steve.
>|||> No. Either select * from
Ugh, in a production query? IMHO, this is not good advice at all, not only
because of the SELECT * alone, but also because he's going to retrieve 20
columns of data he has no interest in.
How about :
SELECT COLUMN_NAME + ', '
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='table name'
AND COLUMN_NAME LIKE 'cc%'
Then you can take that result from the results pane, and paste it into your
query (removing the trailing comma).
http://www.aspfaq.com/
(Reverse address to reply.)|||molsonexpert wrote:
> I like some help on the syntax for a query: I have a table that has
> about 50 columns. I need to have 30 of the columns in a query using a
> select statement. Since many of the columns are prefixed 'cc', I'd
> like to use a wildcard, instead of typing out each column name. Is
> this possible? For example, select cc* from table, or select cc% from
> table.
> Thanks
> steve.
Or use Query Analyzer. Right click on the table and pick the option to
script a SELECT to a new window and trim those results.
David G.|||Perfect. Thanks, Aaron. By the way, can anyone suggest a good book for SQL,
particularly SQL scripting? SQL help and BOL aren't bad, but I'd like a
reference manual as well. Thanks again.
steve.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:OmqxikGkEHA.632@.TK2MSFTNGP12.phx.gbl...
> Ugh, in a production query? IMHO, this is not good advice at all, not
only
> because of the SELECT * alone, but also because he's going to retrieve 20
> columns of data he has no interest in.
> How about :
> SELECT COLUMN_NAME + ', '
> FROM INFORMATION_SCHEMA.COLUMNS
> WHERE TABLE_NAME='table name'
> AND COLUMN_NAME LIKE 'cc%'
> Then you can take that result from the results pane, and paste it into
your
> query (removing the trailing comma).
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>|||http://www.aspfaq.com/2423
http://www.aspfaq.com/
(Reverse address to reply.)
"molsonexpert" <imdrunk@.work.ca> wrote in message
news:eBp8JVPkEHA.1348@.TK2MSFTNGP15.phx.gbl...
> Perfect. Thanks, Aaron. By the way, can anyone suggest a good book for
SQL,
> particularly SQL scripting? SQL help and BOL aren't bad, but I'd like a
> reference manual as well. Thanks again.
> steve.
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:OmqxikGkEHA.632@.TK2MSFTNGP12.phx.gbl...
> only
20[vbcol=seagreen]
> your
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment